2013-03-20 69 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