很多时候,不知道需要表单的数目,就需要能对表单进行数量的控制。收集了如下两个效果:
效果1:
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
效果2:
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
在asp中,动态表单可按普通表单一样进行提交。简易的方法是设定一个固定表单的name,当有多个表单提交时,各表单数据会自动用","隔开,然后用split进行分割,再循环进行分别提交。如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <script language="javascript"> function addTxtProductNameBox() { var oTb = document.getElementById("TableProductName"); var oTr = oTb.insertRow(0); oTr.insertCell(0).innerHTML ="<input name='txtProductName' type='text'><input type=button onclick='return delTxtProductNameBox(this)' value='删除'>" return false; } function delTxtProductNameBox(obj) { obj.parentElement.parentElement.removeNode(true); return false; } </script> <% dim rs3,sql3,productNameArray if productName<>"" then set rs3=server.CreateObject ("ADODB.RecordSet") sql3="select * from AmdiProduct" rs3.open sql3,conn,3,2 productNameArray=split(productName,",") for i = 0 to ubound(productNameArray) rs3.addnew rs3("CompanyID")=companyId rs3("ProductName")=productNameArray(i) rs3.update next rs3.close set rs3=nothing end if %> <form name="form1" method="post" action=""> 产品名称:<a href="#" onclick="addTxtProductNameBox()">添加产品名称</a> <table id="TableProductName" border=0> <tr><td> </td></tr> </table> <input name="submit" type="submit" id="submit" value="== 提交 ==" /> </form>