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里頁面中元素的值 測(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哥說:';
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>
相關(guān)文章
javascript中SetInterval與setTimeout的定時(shí)器用法
Javascript的setTimeOut和setInterval函數(shù)應(yīng)用非常廣泛,它們都用來處理延時(shí)和定時(shí)任務(wù),比如打開網(wǎng)頁一段時(shí)間后彈出一個(gè)登錄框,頁面每隔一段時(shí)間發(fā)送異步請(qǐng)求獲取最新數(shù)據(jù)等,本文文章通過代碼示例給大家介紹javascript中SetInterval與setTimeout的定時(shí)器用法2015-08-08javaScript中push函數(shù)用法實(shí)例分析
這篇文章主要介紹了javaScript中push函數(shù)用法,較為詳細(xì)的分析了javascript中push函數(shù)的功能、定義及使用技巧,需要的朋友可以參考下2015-06-06比較詳細(xì)的關(guān)于javascript中void(0)的具體含義解釋
比較詳細(xì)的關(guān)于javascript中void(0)的具體含義解釋...2007-08-08微信小程序云開發(fā)修改云數(shù)據(jù)庫中的數(shù)據(jù)方法
這篇文章主要介紹了微信小程序云開發(fā)修改云數(shù)據(jù)庫中的數(shù)據(jù)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05javascript深拷貝的原理與實(shí)現(xiàn)方法分析
這篇文章主要介紹了javascript深拷貝的原理與實(shí)現(xiàn)方法,簡單分析了值傳遞和引用傳遞的原理與實(shí)現(xiàn)方法,并結(jié)合實(shí)例形式給出了深拷貝的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-04-04