2013-03-20 73 views
-3

php代碼, 這是一個使用javascript創建輸入的小函數,然後將這些上傳的文件發佈到下一頁。 它在IE上運行良好,但在FF上失敗。它只會傳遞第一個也是唯一不是由js addMore()創建的文件。 IE: 陣列([名稱] =>數組([0] => j1.jpg))Firefox不通過javascript函數創建的輸入值; IE工程

FIREFOX 陣列([名稱] =>數組([0] => j1.jpg 1 => J2 .jpg 2 => j3.jpg)

一位朋友告訴我,由js DOM創建的新節點不適合舊帖子... DOM協議...所以FF無法識別它.. 。是這樣嗎?如何糾正,謝謝

// html content 


<td id="div1"> 
<input name="upload[]" id="upload" type="file" style="width:250px;" />     
<input name="button" type="button" onClick="addMore()" value="+"> 
<br /> to add more files, please click the "+" button 
</td> 


// js content 
<script language="javascript"> 
    var addMore = function() 
{ 

    var div = document.getElementById("div1"); 
    var br = document.createElement("br"); 
    //var input = document.createElement("input"); 
    var input = navigator.userAgent.indexOf("MSIE")>0 ? document.createElement("<input name=\"upload[]\">") : document.createElement("input"); 
    var button = document.createElement("input"); 

    input.setAttribute("type", "file"); 
    input.setAttribute("name", "upload[]"); 
    input.setAttribute("id", "upload"); 
    button.setAttribute("type", "button"); 
    button.setAttribute("value", "-"); 
    button.onclick = function() 
    { 
     div.removeChild(br); 
     div.removeChild(input); 
     div.removeChild(button); 
    } 
    div.appendChild(br); 
    div.appendChild(input); 
    div.appendChild(button); 

} 
</script> 
+0

在非IE瀏覽器中產生了什麼HTML /錯誤? – 2013-03-20 07:52:35

回答

0

嘗試jQuery來做到這一點。你不需要編寫這些代碼。jQuery.clone()會做的工作。如果你需要更多的東西那麼你可以使用this plugin來簡單地通過跨瀏覽器支持來達到預期的結果。這是一個demo of the plugin

+0

謝謝,它有助於你的演示。但jQuery.clone()可以複製一個輸入,但值仍然不會傳遞到下一頁...結果仍然是我的舊代碼... firefox ... – 2013-03-20 08:33:09

+0

再次感謝...在我的第二次檢查,這是正確的關於我的朋友的建議,所謂的DOM規範協議...因爲我的HTML結構是基於表,然後窗體標籤必須包含整個... – 2013-03-20 08:55:20