手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >javascript 获取iframe里页面中元素值的方法
javascript 获取iframe里页面中元素值的方法
摘要:IE方法:document.frames['myFrame'].document.getElementById('test').value;...

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'></iframe>

<input type="button" id="btn" 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里页面中元素值的方法】相关文章:

jQuery获取字符串中出现最多的数

javascript自定义右键弹出菜单实现方法

Javascript动态创建表格及删除行列的方法

JavaScript对表格或元素按文本,数字或日期排序的方法

js实现文本框选中的方法

javascript中CheckBox全选终极方案

javascript去除空格方法小结

JavaScript中的anchor()方法使用详解

Javascript中的getUTCHours()方法使用详解

讲解JavaScript中for...in语句的使用方法

精品推荐
分类导航