日期:2008-12-18  浏览次数:20898 次

  您在看了这些源代码后,可能会注意到有两个类型都为text的form项元素:一个名字为items、一个名字为newItem。为什么呢?这是因为我们要区别哪些是用户通过点击<添加>按钮、并且输入了新值后得到的,哪些是我们为了让用户能够有地方可以输入新值的类型为text的form项元素。这样我们就能很清楚的在循环时只列出用户已经添加的、有值的类型为text的form项元素了。这就是我们为什么把它们命名成不同的名字的缘故,是不是很妙呢?呵呵 :-)。其实这种方法的关键在于利用了request.form("TextFieldName")的Count属性和request.form("TextFieldName")(I)的方法,才使得我们更容易的获取名为TextFieldName的类型为text的form项元素的数目和分别获取它们的值。这两种方法的用处很大,可以大大的简化我们所要编写的代码。大家一定要记住了这两种用法。下面我再给出一个没有用到这两种用法的ASP程序源代码,大家比较比较,体会一下为什么上面的代码要好。

'/*DynamicAddForm2.ASP文件的源代码开始点*/
<%@ Language=VBScript %>
<%
'----------------------------------------------------
'Author : WaiWai(歪歪)
'Created Date : 2000/1/13
'File Name : DynamicAddForm.ASP
'Description : Dynamic Add Form's Text Fields.
'All Rights Reserved.所有权归City Club
'----------------------------------------------------
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<style type="text/CSS">
<!--
td { font-size: 9pt}
body { font-size: 9pt}
select { font-size: 9pt}
A {text-decoration: none; color: #003366; font-size: 9pt}
A:hover {text-decoration: underline; color: #FF0000; font-size: 9pt}
-->
</style>
<title>Add new mail server site. All Rights Reserved.</title>
<script language=javascript>
function mycheck(tt) {
alert("afd")
return false
}
</script>
<BODY topmargin=12>
<form name=form1 method=post>
<table border="1" cellspacing="0" height=400 width=98% bordercolorlight="#5E5E00" bordercolordark="#FFFFEC" bgcolor=LightGrey align=center valign=top>
<td align=center colspan=5 valign=top height=30>
<h4>追加新邮件服务器信息</h4>
</td><tr>
<td align=center valign=top height=10><font style="font-size:11pt">条数</font></td>
<td align=center valign=top height=10 width=43%><font style="font-size:11pt">邮件服务器URL</font></td>
<td align=center valign=top height=20 width=17%><font style="font-size:11pt">用户名参数变量</font></td>
<td align=center valign=top height=20 width=17%><font style="font-size:11pt">密码参数变量</font></td>
<td align=center valign=top height=20 width=17%><font style="font-size:11pt">站点名称</font></td>
<tr>
<td colspan=5 valign=top height=30>
<font color=blue>[ * * * Example: * * * ]<br>
0.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;990.net/

prog/login?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;

&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pass&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;990.net
</font>
</td>
<tr>
<%
if trim(Request.form("num"))="" then
'/*此时表示用户首次打开此ASP页,所以所得的num为空,并显示出相应的输入界面供用户输入信息
'其中的num值是为来记录类型为text的form元素的数目,与第一个代码文件中的 'request.form("items").Count效果一样.*/
'/*First time open this page.*/
Response.Write "<td align=center valign=top>1.</td>"
Response.Write "<input type=hidden name=num value=1>"
Response.Write "<td align=center valign=top >"
Response.Write "&nbsp;&nbsp;<input typ