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");
    }

  • 相关阅读:
    002使用代码和未经编译的XMAL文件创建WPF程序
    001使用代码创建WPF应用程序
    制作地图PPT
    数据库基本知识学习(sql server)
    虚拟现实技术对人类是福还是祸?
    计算机中的数学
    软件架构
    extracts
    bootstrap
    omron欧姆龙自动化应用
  • 原文地址:https://www.cnblogs.com/jifeng/p/2169850.html
Copyright © 2011-2022 走看看