js实现iframe框架取值的方法(兼容IE,firefox,chrome等)
本文实例讲述了js实现iframe框架取值的方法。分享给大家供大家参考,具体如下:
为啥世上会有这么多不同的浏览器?每次遇到js/css的浏览器兼容性问题,总是要发出这样的感叹,真希望这些个浏览器公司全部倒下,然后只留下一家(显然这是一个不可能实现的美好愿望),言归正传,看代码吧:
iframe框架内页:
<html> <head> <title>框架内页</title> </head> <body> <div> <inputid="txt1"name="txt1"type="text"value="测试"/> </div> </body> </html>
父级类:
<iframename="frame1"id="frame1"src="frm.html"frameborder="1"height="30"></iframe>
<p>
iframe1中文本框的值:</p>
<p>
<inputtype="button"name="Submit"value="getValue"onclick="getValue()"/>
</p>
<scripttype="text/javascript">
functiongetValue(){
varofrm1=document.getElementById("frame1").document;
if(ofrm1==undefined)
{
ofrm1=document.getElementById("frame1").contentWindow.document;
varff=ofrm1.getElementById("txt1").value;
alert("firefox/chrome取值结果为:"+ff);
}
else
{
varie=document.frames["frame1"].document.getElementById("txt1").value;
alert("ie取值结果为:"+ie);
}
}
</script>
希望本文所述对大家JavaScript程序设计有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下