javascript 获取iframe里页面中元素的值
2012-05-27 22:41
429 查看
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内的页面
</title>
</head>
<body>
<input type='text' id="test" value='欢迎访问:justflyhigh.com'>
</body>
</html>
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内的页面
</title>
</head>
<body>
<input type='text' id="test" value='欢迎访问:justflyhigh.com'>
</body>
</html>
相关文章推荐
- javascript 获取iframe里页面中元素值的方法
- javascript 获取iframe里页面中元素值的方法
- javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,
- 网页元素用Javascript获取页面元素的位置
- 用Javascript获取页面元素的位置
- 同一页面的两个Iframe,其中一个iframe获取另一个iframe内的iframe中的元素值
- Javascript获取页面元素的位置
- 用Javascript获取页面元素的位置
- ifram高度自适应,获取iframe元素,控制父页面
- JS与JQ中iframe获取子父级页面元素的方法
- JavaScript获取页面上某个元素的代码
- iframe遇到的坑,如子父页面元素获取报错,iframe.contentWindow == null等等
- javascript 获取父页面中元素对象方法
- iframe父页面获取iframe子页面的元素 与 iframe子页面获取父页面元素
- 用 jQuery 获取 iframe 父页面元素
- javascript 精确获取页面元素的位置
- iframe给主页面元素赋值【使用jquery获取页面数据】
- 用 jQuery 获取 iframe 父页面元素
- iframe 中获取父页面元素
- iframe父、子页面之间页面元素的获取及方法的调用 jquery