8.1 百年日历源代码
Calendar.asp
<%@ Language=VBScript %>
<%
'定义一个函数,用于判断给定月份的天数:
Function GetDays(Yy,Mm)
Select Case Mm
Case 1,3,5,7,8,10,12
GetDays=31
Case 4,6,9,11
GetDays=30
Case 2
If Yy Mod 4<>0 Or (Yy Mod 100=0 And Yy Mod 400<>0) Then
GetDays=28
Else
GetDays=29
End If
End Select
End Function
'获取用户指定的年、月、日:
Dim Yy,Mm,Dd
Yy=Request.QueryString("SY")
Mm=Request.QueryString("SM")
Dd=Request.QueryString("SD")
'如果未做选择,默认为当前系统日期的年、月、日:
If Yy = Empty Then Yy=Year(Date)
If Mm = Empty Then Mm=Month(Date)
If Dd = Empty Then Dd=Day(Date)
%>
<html>
<head>
<title>百年日历</title>
</head>
<body>
<center>
<p><font size="6" face="华文行楷" color="#660033">百年日历</font></p>
<table border="0" width="60%">
<tr bgColor="#000080">
<td width="100%" colspan="7"><p>
<form method="GET" act
<font style="FONT-SIZE: 12pt" color=#ffffff>公元
<!--生成选择年份(1900~2100)下拉列表框,命名为SY:-->
<select size="1" name="SY">
<% For i = 1900 To 2100
If i=CInt(Yy) Then
Response.Write "<option Selected>"&i&"</option>"
Else
Response.Write "<option>"&i&"</option>"
End If
Next %>
</select>年
<!--生成选择月份(1~12)下拉列表框,命名为SM:-->
<select size="1" name="SM">
<% For i = 1 To 12
If i=CInt(Mm) Then
Response.Write "<option Selected>"&i&"</option>"
Else
Response.Write "<option>"&i&"</option>"
End If
Next %>
</select>月
<!--生成选择日期(1~31)下拉列表框,命名为SD:-->
<select size="1" name="SD">
<% For i = 1 To 31
If i=CInt(Dd) Then
Response.Write "<option Selected>"&i&"</option>"
Else
Response.Write "<option>"&i&"</option>"
End If
Next %>
</select>日
<input type="submit" value="刷新" name="Go">
</form>
</p></td>
</tr>
<tr align=middle bgColor="#e0e0e0">
<td width="14%" align="center">日</td>
<td width="14%" align="center">一</td>
<td width="14%" align="center">二</td>
<td width="14%" align="center">三</td>
<td width="14%" align="center">四</td>
<td width="15%" align="center">五</td>
<td width="15%" align="center">六</td>
</tr>
<tr align=center>
<%
Dim Dow '当月1日为星期几
Dim Days '当月的总天数
Dim Posi '当日的输出位置
Dim Num '表示当日的输出数字
'利用WeekDay函数获取当月1日为星期几:
Dow = WeekDay(CDate(Mm&"/1/"&Yy))
'利用自定义函数获取本月的天数:
Days = GetDays(Yy,Mm)
'如果当月1日不是星期天,则先输出若干空白表格单元:
If Dow<>1 Then
For i = 1 To Dow-1
Response.Write "<td></td>"
Next
End If
'设定当月第1日输出的位置:
Posi = Dow
'利用循环在相应位置输出当月的每一天,
For Num = 1 To Days
'若为当天用高亮显示:
If Num=CInt(Dd) Then
Response.Write "<td bgcolor=#00ffff>"
Response.Write "<font size=5 face=Arial color=green>"
Else
'若为周日或周六用红字显示,其余用黑字显示:
If Posi=1 or Posi=7 Then
Response.Write "<td><font size=5 face=Arial color=red>"
Else
Response.Write "<td><font size=5 face=Arial color=black>"
End If
End If
Response.Write "<b>"&Num&"</b></font></td>"
Posi=Posi+1
If Posi=8 Then
Response.Write "</tr><tr align=center>"
Posi=1
End If
Next
%>
</tr>
</table>
</center>
</body>
</html>
评论