2014-04-10 72 views
-1

通过添加按钮添加额外字段的此查询正在Google chrome上工作,但不在Internet Explorer中。请帮我解决它在IE 11中。通过添加按钮添加额外字段

<html> 
    <head> 
    <script>  
     function add_field() 
     { 
      var form = document.getElementsByTagName('form')[0], 
      input = document.createElement('input'); 
      input.setAttribute('type', 'text'); 
      input.setAttribute('name', 'item'); 
      form.appendChild(input); 
     }; 
    </script> 



    <form name="input" method="get"> 
     <div class="ui-input-text"> 
      <input type="text" name="item"><br> 
      <div data-role="navbar"> 
       <button type="button" onclick="add_field 

    ()">ADD</button><br> 
      </div> 
     </div> 
    </form> 

    </body> 
    </html> 
+0

在IE9中工作正常。 – ponciste

+1

Javascript控制台中是否有任何错误? – Barmar

+0

为什么使用全局变量'input'而不是局部变量? – Barmar

回答

0

根据我的经验,互联网探险家(各种版本)有问题分配“名称”属性元素。我发现以下自定义方法适用于任何情况:

Element.prototype.customAttribute=function(customname, customvalue){ 
var z=document.createAttribute(customname); 
z.value=customvalue; 
this.setAttributeNode(z); 
} 
0

脚本工作正常,但您需要允许它在站点上运行脚本。 Internet Explorer将阻止该脚本,直到用户确认他/她希望它运行。

Internet Explorer中运行脚本或ActiveX控件

我使用了Internet Explorer 11在Windows 7 64位阻止此网页。没有错误发生,一切正常。