javascript 獲取iframe里頁面中元素值的方法
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哥說:';
tmp += document.frames['myFrame'].document.getElementById('test').value;
}else{
tmp = document.getElementById('myFrame').contentWindow.document.getElementById('test').value;
}
alert(tmp);
}
示例代碼:
a.html頁面中的代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
javascript 獲取iframe里頁面中元素的值 測試
</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哥說:';
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頁面中的代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
我是 iframe內(nèi)的頁面
</title>
</head>
<body>
<input type='text' id="test" value='歡迎訪問:justflyhigh.com'>
</body>
</html>
相關文章
javascript中SetInterval與setTimeout的定時器用法
Javascript的setTimeOut和setInterval函數(shù)應用非常廣泛,它們都用來處理延時和定時任務,比如打開網(wǎng)頁一段時間后彈出一個登錄框,頁面每隔一段時間發(fā)送異步請求獲取最新數(shù)據(jù)等,本文文章通過代碼示例給大家介紹javascript中SetInterval與setTimeout的定時器用法2015-08-08比較詳細的關于javascript中void(0)的具體含義解釋
比較詳細的關于javascript中void(0)的具體含義解釋...2007-08-08微信小程序云開發(fā)修改云數(shù)據(jù)庫中的數(shù)據(jù)方法
這篇文章主要介紹了微信小程序云開發(fā)修改云數(shù)據(jù)庫中的數(shù)據(jù)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-05-05