<html>
<title>www.ttasp.net(DropDown Menu Dates)</title>
<body bgcolor="#FFFFFF">
<%
'请求所有可能传递的表单元素
u_date=request.form("u_date")
u_month=request.form("u_month")
u_day=request.form("u_day")
u_year=request.form("u_year")
'检查看看表单都是否已经提交
if (u_month <> "") or (u_date <> "") then
%><center>You selected <br>
<% ' If the first form was selected display the user input
if (u_month <> "") then
response.write u_month & "/" & u_day & "/" & u_year
end if
'如果第二个表单被选择出来显示用户输入
if (u_date <> "") then
response.write u_date
end if %>
<% '如果两个表单都没有被选择显示两个表单来设置为今天的日期
else %>
<form action="<%= request.servervariables("script_name") %>" method="post">
<select size="1" name="u_date">
<% '这个循环会创建有过去10天的下拉菜单
for counter = date()-10 to date() %>
<option <% ' select the current date to display it
if counter = date() then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>
<input type="submit">
</form>
<p> </p>
<p> </p>
<form action="<%= request.servervariables("script_name") %>" method="post">
<select size="1" name="u_month">
<% '开始创建一年的12个月的循环
for counter = 1 to 12 %>
<option <% ' Select the current month to display
if counter = month(date()) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>
<select size="1" name="u_day">
<% '开始创建一个月的天数的循环
for counter = 1 to 31 %>
<option <% ' Select the current day to display
if counter = day(date()) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>
<select size="1" name="u_year">
<% '开始创建预先和以前的年份的循环
for counter = 1998 to 2005 %>
<option <% ' Select the current year to display
if counter =year(date()) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>
<input type="submit">
<% end if %>
</body>
</html>
用户在应用程序里面输入日期有很多种方式。下拉菜单的话算是很不错的方法,一般来说的话,下拉菜单输入比文本框输入会出现的错误会更少。利用这个日期()函数当前日期(或者通过调整日期值来符合你对任何的日期的需要)能很容易地由预充的选项值操作出来。两个例子中的第一个的话显示了有之前日期范围的当前日期。第二个显示了所有的年份范围的当前日期、
热门信息
阅读 (201)
1 独特的随机字母阅读 (175)
2 检查和设置IIS服务器正确的权限阅读 (167)
3 asp网站伪静态化URL Rewrite中的httpd.ini伪静态化规则编写方法阅读 (166)
4 asp取access数据库里本周、本月、本季度的记录~阅读 (166)
5 ASP-对象