javascript 獲取iframe里頁(yè)面中元素值的方法
IE方法:
document.frames['myFrame'].document.getElementById('test').value;
火狐方法:
document.getElementById('myFrame').contentWindow.document.getElementById('test').value;
IE、火狐方法:
function getValue(){
var tmp = '';
if(document.frames){
tmp += 'ie哥說(shuō):';
tmp += document.frames['myFrame'].document.getElementById('test').value;
}else{
tmp = document.getElementById('myFrame').contentWindow.document.getElementById('test').value;
}
alert(tmp);
}
示例代碼:
a.html頁(yè)面中的代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
javascript 獲取iframe里頁(yè)面中元素的值 測(cè)試
</title>
</head>
<body>
<iframe id="myFrame" src='b.html' style="width:300px;height: 50px;"></iframe>
<input type="button" id="btn" onclick="getValue()" value="test" >
<script type="text/javascript">
function getValue(){
var tmp = '';
if(document.frames){
tmp += 'ie哥說(shuō):';
tmp += document.frames['myFrame'].document.getElementById('test').value;
}else{
tmp = document.getElementById('myFrame').contentWindow.document.getElementById('test').value;
}
alert(tmp);
}
</script>
</body>
</html>
b.html頁(yè)面中的代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
我是 iframe內(nèi)的頁(yè)面
</title>
</head>
<body>
<input type='text' id="test" value='歡迎訪問(wèn):justflyhigh.com'>
</body>
</html>
相關(guān)文章
符合W3C Web標(biāo)準(zhǔn)的圖片連續(xù)無(wú)間隙水平滾動(dòng)
很久以前就有這個(gè)問(wèn)題,總是找不到通用的,或比較簡(jiǎn)單的“圖片連續(xù)無(wú)間隙向左滾動(dòng),無(wú)間隙向右滾動(dòng),符合W3C Web標(biāo)準(zhǔn)”2008-06-06
JavaScript Array實(shí)例方法flat的實(shí)現(xiàn)
flat() 方法用于將一個(gè)嵌套多層的數(shù)組進(jìn)行扁平,返回新數(shù)組,它不會(huì)改變?cè)紨?shù)組, flat 方法在處理多維數(shù)組時(shí)非常有用,它可以讓數(shù)組操作變得更加靈活和簡(jiǎn)潔,本文給大家介紹了JavaScript Array實(shí)例方法flat的實(shí)現(xiàn),需要的朋友可以參考下2024-03-03
基于jquery的高性能td和input切換并可修改內(nèi)容實(shí)現(xiàn)代碼
在實(shí)際工作中,我們會(huì)碰到這樣一個(gè)情況。在頁(yè)面中顯示著100個(gè)數(shù)據(jù),同時(shí)用戶還希望他可以更改其中的數(shù)據(jù),普通的方式可能如下2011-01-01
小程序?qū)崿F(xiàn)錨點(diǎn)滑動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)錨點(diǎn)滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09
JS通過(guò)調(diào)用微信API實(shí)現(xiàn)微信支付功能的方法示例
這篇文章主要介紹了JS通過(guò)調(diào)用微信API實(shí)現(xiàn)微信支付功能的方法,結(jié)合具體實(shí)例形式分析了javascript微信支付接口的調(diào)用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-06-06

