-------------------------------------aspx-------------------------
<table>
<tr valign="top">
<td>附件</td>
<td>
<div style="float:left; width:30px">
<input type="button" value="+" onclick="addFile()" />
</div>
<div id="divFile" style="float:left">
<div>
<input type="file" style="width:400px" runat="server" name="files">
<asp:Button ID="btnSubmit" runat="server" Text="提交" OnClick="btnSubmit_Click" />
</div>
</div>
</td>
</tr>
</table>
<script type="text/javascript">
function addFile()
{
var divFile = document.getElementById('divFile');
var fileCount = divFile.getElementsByTagName("div").length;
if(fileCount<5)//根据情况做个限制
{
var str = '<div><input type="file" style="width:400px" runat="server" name="files"><img id="imgAdd" src="../../Images/colj1.gif" onclick="deleteFile(this)" /></div>';
divFile.insertAdjacentHTML("beforeEnd",str);
}
else
{
alert("最多增加五个");
}
}
function deleteFile(child)
{
var divFile = document.getElementById("divFile");
divFile.removeChild(child.parentNode);
}
</script>
--------------------------------------aspx.cs------------------------------------
protected void btnSubmit_Click(object sender, EventArgs e)
{
HttpFileCollection myFile = HttpContext.Current.Request.Files;
int iFileCount = myFile.Count;
lblShow.Text = iFileCount.ToString();
for (int i = 0; i < iFileCount; i++)&sh
···
···