为什么当我上传文件并点击更多上传另一个文件时,第一个删除?
<table align="right" border="1" cellpadding="2">
<tr>
<td class="auto-style45" id="theadder"><input type="file" name="the_file_24"> <br><br></td>
<td>Here you<br> can upload <br>your files<br>
<span align="right" style="cursor:pointer;" id="adduploadinput" onclick="javascript:addInput('theadder')">more+</span>
</td>
</tr>
</table>
<!--this the javascript function thats add more files-->
<script>
var inc=1;
function addInput(x){
document.getElementById(x).innerHTML += "<input id=filee"+inc+" type=file name=the_file_24> <br><br>";
inc++;
}
</script>
除了写得很糟糕的HTML之外,您的问题就在这里:
name=文件_24
将+inc部分添加到名称中,就像您对id所做的那样,并在接收代码中考虑到这一点,它应该会起作用。
事实上,所有文件输入都有相同的名称,因此它们会相互覆盖。