AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

js实现iframe框架取值的方法(兼容IE,firefox,chrome等)

51自学网 http://www.wanshiok.com
js,iframe框架,取值,js实现iframe框架取值

本文实例讲述了js实现iframe框架取值的方法。分享给大家供大家参考,具体如下:

为啥世上会有这么多不同的浏览器?每次遇到js/css的浏览器兼容性问题,总是要发出这样的感叹,真希望这些个浏览器公司全部倒下,然后只留下一家(显然这是一个不可能实现的美好愿望),言归正传,看代码吧:

iframe框架内页:

<html><head>  <title>框架内页</title></head><body>  <div>    <input id="txt1" name="txt1" type="text" value="测试" />  </div></body></html>

父级类:

<iframe name="frame1" id="frame1" src="frm.html" frameborder="1" height="30"></iframe><p>  iframe1中文本框的值:</p><p>  <input type="button" name="Submit" value="getValue" onclick="getValue()" /></p><script type="text/javascript">function getValue(){  var ofrm1 = document.getElementById("frame1").document;  if (ofrm1==undefined)  {    ofrm1 = document.getElementById("frame1").contentWindow.document;    var ff = ofrm1.getElementById("txt1").value;    alert("firefox/chrome取值结果为:" + ff);  }  else  {    var ie = document.frames["frame1"].document.getElementById("txt1").value;    alert("ie取值结果为:" + ie);  }}</script>

希望本文所述对大家JavaScript程序设计有所帮助。


js,iframe框架,取值,js实现iframe框架取值  
上一篇:深入浅析同源策略和跨域访问  下一篇:学习JavaScript设计模式(单例模式)