zoukankan      html  css  js  c++  java
  • iframe框架取值兼容ie/firefox/chrome的写法

    为啥世上会有这么多不同的浏览器?每次遇到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>
    作者:菩提树下的杨过
    出处:http://yjmyzz.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    About “condition variables”
    路由表的读法(zz)
    C++字符串之一(字符表示)
    Audio Codec Summary
    关于telnet
    C++ 之 new
    (转)让ubuntu9.10开机自动挂载NTFS分区
    WorkSpace And Static Library In GarbageXcode4
    mac os x 10.7下配置svn服务器
    ubuntu下设置双显示器扩展桌面
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/1496539.html
Copyright © 2011-2022 走看看