上一篇文章講到了動態添加表單元素,這次我們來講講怎麼樣來處理這些動態添加的表單元素傳過來的數據! 怎麼樣動態添加表單元素,我這裡就不細說了!不明白的看看上一篇文章//www.Vevb.com/html/200711/23/12856.htm下面是動態添加表單元素的頁面代碼!
複製代碼代碼如下:
<html>
<head>
<title>動態添加表單元素BlueShine</title>
</head>
<scriptlanguage="javascript">
functionAddElement(mytype){
varmytype,TemO=document.getElementById("add");
varnewInput=document.createElement("input");
newInput.type=mytype;
newInput.name="input1";//這個是必須的,在處理頁中要用到!
TemO.appendChild(newInput);
varnewline=document.createElement("br");
TemO.appendChild(newline);
}
</script>
<body>
<formaction="getdata.asp"method="post"name="frm">
<pstyle="background:#FFEC8B;border:solid1px#1E90FF;font-size:13px;line-height:200%;width:100px;text-align:center"><astyle="color:#218868;"href="javascript:void(0)"onClick="AddElement('text')">添加文本框</a></p>
<pid="add"></p>
<label>
<inputtype="submit"name="Submit"value="提交">
</label>
<label>
<inputtype="reset"name="Submit2"value="重置">
</label>
</form>
</body>
</html>
下面是數據處理頁面代碼:
複製代碼代碼如下:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>動態添加表單元素</title>
</head>
<body>
<divstyle="font-size:13px"><%
dimdata,arr,n
data=Trim(Request.Form("input1"))'這就是在代碼中定義的name屬性
arr=split(data,",")'用Split函數對數據進行分割!
Response.Write("這是未分割的數據:")
Response.Write(data)
Response.Write("<br>")
Response.Write("<br>")
Response.Write("這是用Split函數分割後的數據:")
Response.Write("<br>")