关闭顶部展开顶部

ASP实现动态添加表单内容的实例程序_ASP教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:ASP教程:透彻掌握ASP分页技术
近段时间看了一些论坛上面关于分页的ASP程序依然有许多的关注者,但里面只有代码,没有详细的解释,对于初学者来说,这样总是得不到真正的掌握,此次我将针对分页技术进行详解,让大家来理解ASP

很多时候,不知道需要表单的数目,就需要能对表单进行数量的控制。收集了如下两个效果:

以下为引用的内容:
<html>
<body>
<form name="form1">
<table id="tb1" border=0>
<tr><td><a href="#" onclick="return addFj()">添加附件</a></td></tr>
</table>
<input type="hidden" name="fjCnt" value="1" />
</form>
</body>
</html>
<script language="javascript">
function addFj()
{
var oTb = document.getElementById("tb1");
var oTr = oTb.insertRow(0);
var name = "thefilename" document.form1.fjCnt.value;
document.form1.fjCnt.value=parseInt(document.form1.fjCnt.value) 1;
oTr.insertCell(0).innerHTML = "<input id='file' name='" name "' type=file style='width:400px;'> <input type=button onclick='return delFj(this)' value='删除'>"
return false;
}
function delFj(obj)
{
obj.parentElement.parentElement.removeNode(true);
return false;
}
</script>

以下为引用的内容:
<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--
.p9{ font-size: 9pt; font-family: 宋体 }
td {font-size: 9pt}
.tx {height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #eeeeee; color: #0000FF}
.tx2 {height: 16px;border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; color: #0000FF; border-left-color:#000000; border-right-color:#000000; border-top-color:#000000; border-bottom-color:#000000}
.bt {border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; font-size: 9pt; border-right-width: 1; border-bottom-width: 1; height: 16px; width: 80px; background-color: #EEEEEE; cursor: hand; border-right-style:solid; border-bottom-style:solid}
.tx1 { width: 400 ;height: 20px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}
-->
</STYLE>
<SCRIPT LANGUAGE="vbscript">
function addfile()
dim str
str="<table>"
if not IsNumeric (window.form1.filenum.value) then window.form1.filenum.value =1
for i=1 to window.form1.filenum.value
str=str&"<tr><td valign='middle'>文件"&i&":</td><td><input type='file' name='file"&i&"' class='tx1' value size='20'>  保存为<input type='text' name='file"&i&"' size='20' class='tx2'></td></tr>"
next
window.uptd.innerHTML =str&"</table>"
end function
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Show()
{
var allnum =document.form1.filenum.value;//获取有几个file
for (i=0;i<allnum;i )
{
alert("文件框的Name:file" i);
}
return false;
}
//-->
</SCRIPT>
<TITLE></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"></HEAD>
<BODY BGCOLOR="#ffffff" CLASS="p9" onLoad="addfile()">
<FORM METHOD="post" NAME="form1" ACTION="savetofile.asp" ENCTYPE="multipart/form-data">
<TABLE BORDER="0" ALIGN="center" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD><DIV ALIGN="center"><FONT COLOR="#0000ff" SIZE="5">保存到文件</FONT></DIV></TD>
</TR>
<TR>
<TD><TABLE WIDTH="750" BORDER="1" ALIGN="center" CELLPADDING="0" CELLSPACING="0" BORDERCOLOR="#111111" STYLE="BORDER-COLLAPSE: collapse">
<TR>
<TD HEIGHT="27" COLSPAN="2">上传
<INPUT NAME="filenum" CLASS="tx2" VALUE="1" SIZE="4">
个文件  
<INPUT TYPE="button" NAME="Button" CLASS="bt" onClick="addfile" VALUE="设 定">
</TD>
</TR>
<TR>
<TD> <DIV ID="uptd"> </DIV></TD>
</TR>
<TR>
<TD HEIGHT="30" COLSPAN="2" ALIGN="middle">
<INPUT TYPE="Button" NAME="Button" CLASS="bt" VALUE="看看有几个框" onclick="Show()">
<INPUT TYPE="submit" NAME="Button" CLASS="bt" VALUE="上 传">
  
<INPUT TYPE="reset" NAME="Button" CLASS="bt" VALUE="重 置">
</TD>
</TR>
</TABLE></TD>
</TR>

</TABLE>
</FORM>
</BODY>
</HTML>

在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>

分享:简单ASP论坛DIY
首先用Access新建一个数据库,设取名为luntan,数据表的名称为“information”,建立如下字段:“text”,“name”,“time”,并将“time&rdquo

来源:模板无忧//所属分类:ASP教程/更新时间:2008-08-22
loading.. 评论加载中....
相关ASP教程
闁汇埄鍨遍悺鏇綖閸℃稒鈷掓い鏇楀亾妞わ綇鎷�
婵炲濮崑鎾斥槈閺傝法澧涙俊鑼€濋柣銏╁灲閹凤拷
婵犵鈧啿鈧绱炲澶嬪殧鐎瑰嫭澹嗙换涔侀柣銏╁灲閹凤拷
婵犵鈧啿鈧绱炲澶婄闁诡垎鍕槬闁诲酣娼уΛ娑㈡偉閿燂拷
闂佺ǹ绻愰幊搴ㄥ焵椤掑倸甯堕幖瀛樼矒瀹曟繈鏁撻敓锟�
闂佺ǹ绻愰幊搴ㄥ焵椤掆偓閸氬绮婇敂鍓х煓閻庯絺鏅濋惌娆戠磽娓氬﹥瀚�
闂佽 鍋撴い鏍ㄧ☉閻︻噣鏌涘┑鎰胺缂併劍妞藉銊╊敍濞嗘垵绗¢梺鍝勫€婚幊鎾舵閿燂拷
闂佸搫鍟版慨椋庣礊婢舵劖鐓i悹杞拌濞层倕霉閿濆棙绀€闁告ɑ鐗犲畷鎰版晸閿燂拷
濠碘槅鍨崜婵嗩熆濡吋瀚绘い鎾寸箖鐎氾拷
婵犵鈧啿鈧绱炲鍥ㄥ妞ゆ挻绻冪€氳櫕淇婇妤€澧叉繝顫嫹
濠碘槅鍨崜婵嗩熆濮椻偓瀹曨剟顢欓崗鐓庘偓鐢告煛閸繄孝濠殿噯鎷�
濠碘槅鍨崜婵嗩熆濮椻偓閺屽懘鍩€椤掆偓閳诲酣骞戦幇闈涙闂佸搫瀚搁幏锟�
濠碘槅鍨崜婵嗩熆濮椻偓瀹曪綁骞嬪┑鍫紝
婵犵鈧啿鈧绱炲澶婄煑闁瑰瓨绻勯瀛樹繆椤栨澧叉繝顫嫹
闁诲骸鍘滈崜婵嬫偋閹惰棄鐭楀┑鐘插暙閼靛綊鏌ら懞銉ュ闁绘牭缍佸畷娆撴晸閿燂拷
UB闂佸湱绮崝妤呯嵁閸モ晜瀚氶悗娑櫳戦~锟�
闂佽壈椴稿濠氭焾鐎电硶鍋撻獮鍨仾婵犫偓閿燂拷
闁诲骸绠嶉崹鍝勶耿閸㈢嚜
闂佸憡姊绘慨椋庣礊婢跺瞼鍗氭繛鍡楀閸炲绻涚紙鐘哄厡闁稿骏鎷�
缂傚倷鐒﹂悷锕傚垂濠婂嫮顩锋い鎺嶇缁插湱鈧偣鍊濈紓姘额敊閿燂拷
©2017 www.mb5u.com濠碘槅鍨崜婵嗩熆濮椻偓瀵噣鎮╅幓鎺撳瘶
闂佽 鍋撻柟顖滃椤ワ拷&闂佸憡甯掑Λ鏃堟閿燂拷