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 Array實例方法flat的實現(xiàn)
flat() 方法用于將一個嵌套多層的數(shù)組進行扁平,返回新數(shù)組,它不會改變原始數(shù)組, flat 方法在處理多維數(shù)組時非常有用,它可以讓數(shù)組操作變得更加靈活和簡潔,本文給大家介紹了JavaScript Array實例方法flat的實現(xiàn),需要的朋友可以參考下2024-03-03
基于jquery的高性能td和input切換并可修改內(nèi)容實現(xiàn)代碼
在實際工作中,我們會碰到這樣一個情況。在頁面中顯示著100個數(shù)據(jù),同時用戶還希望他可以更改其中的數(shù)據(jù),普通的方式可能如下2011-01-01
JS通過調(diào)用微信API實現(xiàn)微信支付功能的方法示例
這篇文章主要介紹了JS通過調(diào)用微信API實現(xiàn)微信支付功能的方法,結合具體實例形式分析了javascript微信支付接口的調(diào)用方法與相關注意事項,需要的朋友可以參考下2017-06-06

