zoukankan      html  css  js  c++  java
  • IE、Firefox兼容form target当前页iframe,javascript动态创建表单对象form设置name属性

    一、

    不兼容的测试代码:

      <body>
        
    <form  action="http://www.baidu.com" method="post" id="form_forwrad_forword" >
            
    <input type="submit" value="submit"/>
        
    </form>
        
        
        
    <iframe id="loginIframe"   width="300" height="300"></iframe>
      
    </body>
    </html>
    <script language="javascript">
        
    var _form=document.getElementById("form_forwrad_forword");
        _form.setAttribute(
    "target","loginIframe");
    </script>

     IE:点击“submit”提交之后,form表单并未按照预想提交到“loginIframe”这个iframe中。

    FF:点击“submit”提交之后,form表单按照预想提交到“loginIframe”这个iframe中。

    解决此兼容问题: 在iframe中增加name属性即name=“loginIframe

    <iframe id="loginIframe"  name="loginIframe" width="300" height="300"></iframe>

    二、解决javascript动态创建表单对象form设置name属性(IE、FF兼容)


    function AFTER_FORMCREATE_FN(){
        
    var _iframe;
        
    try { // for I.E.
            _iframe= document.createElement('<iframe name="loginIframe">');
        } 
    catch (ex) { //for other browsers, an exception will be thrown
            _iframe = document.createElement('iframe'); 
        }
        
        _iframe.setAttribute(
    "id","loginIframe");
        _iframe.setAttribute(
    "name","loginIframe");
        _iframe.setAttribute(
    "height","300");
        _iframe.setAttribute(
    "style","display:none;");   
        document.body.appendChild(_iframe); 
           
        
    var _form=document.getElementById("form_forwrad_forword");
        _form.setAttribute(
    "target","loginIframe");
    }

  • 相关阅读:
    Hashmap
    string字符串分词
    关于链表的几道经典例题
    【C语言】链表(LinkedList)的建立与基本操作
    01迷宫
    2019 数学联赛 题解 / 游记
    一种简单方法构造 n 元有限域
    Python逆向某网站之 AES解密数据
    我发现了一个网站Bug,然后反馈了
    在多线程中使用静态方法是否有线程安全问题
  • 原文地址:https://www.cnblogs.com/jifeng/p/2169850.html
Copyright © 2011-2022 走看看