高手帮忙看看,下面的JAVASCRIPT为什么不能动态的增加<input type="file" name="file" />
<head runat="server">
<title>无标题页</title>
<script language ="javascript" type ="text/javascript" >
function addfile()
{
var str ='<br><input type="file" name="file" />'
document.getElementById ('FileCollection').insertBefore ("beforeEnd",str);}
</script>
</head>
<body> <form id="UpMoreFile" runat="server" method ="post" enctype ="multipart/form-data" >
<p id="FileCollection" ><input type ="file" name ="file" /></p>
<p><input onclick ="addfile()" type ="button" value ="增加文件"/></p>
<asp:Button ID ="btu" runat ="server" Text ="UpFile" />
<input id ="rest" value ="重置" type="reset" />
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<script language ="javascript" type ="text/javascript" >
function addfile()
{
var str ='<br><input type="file" name="file" />'
document.getElementById ('FileCollection').insertBefore ("beforeEnd",str);}
</script>
</head>
<body> <form id="UpMoreFile" runat="server" method ="post" enctype ="multipart/form-data" >
<p id="FileCollection" ><input type ="file" name ="file" /></p>
<p><input onclick ="addfile()" type ="button" value ="增加文件"/></p>
<asp:Button ID ="btu" runat ="server" Text ="UpFile" />
<input id ="rest" value ="重置" type="reset" />
</form>
</body>
</html>
<input id ="rest" value ="重置" type="reset" />
我没见过这样的写法,是不是错了?
<html>
<head runat="server">
<title> 无标题页 </title>
<script language ="javascript" type ="text/javascript" >
function addRow() {
var fileCount = 1;
var obj = document.getElementById("attachDiv");
var childObj = document.getElementById("addAttach");
var fileElement;
fileElement = document.createElement("div");
fileElement.id = "attach"+fileCount;
fileElement.style.position = "relative";
fileElement.innerHTML = "<div style='position:relative;'>附 件 :<input id='file"+fileCount+"' type='file' name='file"+fileCount+"'></div><br />";
obj.appendChild(fileElement);
fileCount++;
//alert(obj.innerHTML);
}
</script>
</head>
<body>
<form id="UpMoreFile" runat="server" method ="post" enctype ="multipart/form-data" >
<p id="FileCollection" > <input type ="file" name ="file" /> </p>
<div id="attachDiv" align="left"></div>
<div id="addAttach" align="left"></div> <input name="button" type="button" class="input1" style="cursor: hand;" onClick="addRow();" value="添加附件" /></td>
</tr>
<asp:Button ID ="btu" runat ="server" Text ="UpFile" />
<input id ="rest" value ="重置" type="reset" />
</form>
</body>
</html>