2014-04-10 71 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位阻止此網頁。沒有錯誤發生,一切正常。