遍历所有 input text取值的问题
做一个网络硬盘的东西,其中文件上传部分包括上传文件和每个文件的说明(便于搜索),由于文件可能是多个的,所以需要动态的生成上传文件个数和文件说明
<title> 无标题页 </title>
<script language= "javascript ">
function setid()
{
str= ' ';
if(!document.form1.upcount.value)
document.form1.upcount.value=1;
if (document.form1.upcount.value> 20)
{
alert( '上传数目不能大于20! ');
return false;
}
for(i=1;i <=document.form1.upcount.value;i++)
str+= ' <input type= "file " name= "m_file " contentEditable= "false " id= "m_file " class= "kuan " size= "50 " maxlength= "100 "> 文件描述: <input id= "Text1 " type= "text " /> <br> ';
document.getElementById( "upid ").innerHTML=str+ ' <br> ';
}
</script>
</head>
<body>
<form id= "form1 " runat= "server " method= "post " enctype= "multipart/form-data ">
<div>
需上传的个数 : <input class= "btn " type= "text " size= "7 " value= "5 " name= "upcount " id= "upcount ">
<input onClick= "setid(); " type= "button " value= " 设 定 " name= "Button " >
<br />
<table>
<TR id= "type1 ">
<TD id= "upid "> <P>
<INPUT class= "kuan " contentEditable= "false " id= "m_file " type= "file " maxLength= "100 " size= "50 "
name= "m_file "> 文件描述: <input id= "Text1 " type= "text " /> </asp:TextBox> </P> </TD>
</TR>
</table>
</div>
<asp:Button ID= "Button1 " runat= "server " Text= "Button " />
</form>
</body>
</html>
后台上传文件部分
Dim files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
'状态信息
Dim strMsg As New System.Text.StringBuilder( "上传的文件分别是: <hr color=red> ")
Dim iFile As System.Int32
Try
For iFile = 0 To files.Count - 1
'检查文件扩展名字
Dim postedFile As System.Web.HttpPostedFile = files(iFile)
Dim fileName, fileExtension As System.String
fileName = System.IO.Path.GetFileName(postedFile.FileName)
If Not (fileName = String.Empty) Then
fileExtension = System.IO.Path.GetExtension(fileName)
strMsg.Append( "上传的文件类型: " + postedFile.ContentType.ToString() + " <br> ")
strMsg.Append( "客户端文件地址: " + postedFile.FileName + " <br> ")
strMsg.Append( "上传文件的文件名: " + fileName + " <br> ")
strMsg.Append( "上传文件的扩展名: " + fileExtension + " <br> <hr> ")
'可根据扩展名字的不同保存到不同的文件夹
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath( "images/ ") + fileName)
End If
Next
' strStatus.Text = strMsg.ToString()
Return True
Catch Ex As System.Exception
' strStatus.Text = Ex.Message
Return False
End Try
那么文件说明部分的text的值如何遍历呢?
[解决办法]
: <input id= "Text1给他加一个name= "Text1 "然后在后台用Request.Form[ "Text1 "]得到一个string,号隔开。然后用, split即可得。
[解决办法]
但这样有个问题。如果有户输入了,号则会造成错乱,所以最好在name加上序号
[解决办法]
mark