木子屋 Dnawo's BLOG

一个简单的万年历

👤 dnawo 📅 2006-12-26 👁 5463 👍 0 💬 0 🔄 来源:本站原创
一、VBScript版

HTML
<script language="VBScript">
'       ┯                  ┯
' ┍──┴─────────┴──┓
' |   【函数】                   |
' |    getCount:取得月总天数     |
' |    prevMonth:取得上月地址    |
' |    nextMonth:取得下月地址    |
' |    getPar:取得地址参数       |
' ┗───────────────┛
Function getCount(ByVal iYear,ByVal iMonth)
	Select Case iMonth
		Case 1, 3, 5, 7, 8, 10, 12
			getCount = 31
		Case 4, 6, 9, 11
			getCount = 30
		Case 2
			If IsDate(iyear & "-" & imonth & "-29") Then
				getCount = 29
			Else
				getCount = 28
			End If
	End Select
End Function
Function prevMonth(ByVal iYear,ByVal iMonth)
	Dim temp
	temp = dateadd("m",-1,iYear & "-" & iMonth & "-1")
	iYear = year(temp)
	iMonth = month(temp)
	prevMonth = "?iYear=" & iYear & "&iMonth=" & iMonth
End function
Function nextMonth(ByVal iYear,ByVal iMonth)
	Dim temp
	temp = dateadd("m",1,iYear & "-" & iMonth & "-1")
	iYear = year(temp)
	iMonth = month(temp)
	nextMonth = "?iYear=" & iYear & "&iMonth=" & iMonth
End function
Sub getPar()
	Dim temp,i,j,k,l
	temp = document.location.href
	if instr(temp,"?") = 0 then
		iYear = year(date())
		iMonth = month(date())
	else
		i = len(temp)
		j = instr(temp,"=")
		k = instr(temp,"&")
		l = instrRev(temp,"=")
		iYear = mid(temp,j+1,k-j-1)
		iMonth = right(temp,i-l)
	end if
End sub
'       ┯                  ┯
' ┍──┴─────────┴──┓
' |    【变量】                  |
' |     iPrev:上个月地址         |
' |     iNext:下个月地址         |
' |     iCount:月总天数          |
' |     iSpc:第一行空格数        |
' |     iNum:总单元格数35或42    |
' |     iYear:年份               |
' |     iMonth:月份              |
' ┗───────────────┛
Dim i,j,iPrev,iNext,iCount,iSpc,iNum,iYear,iMonth
Call getPar()
iCount = getCount(iYear,iMonth)
iPrev = prevMonth(iYear,iMonth)
iNext = nextMonth(iYear,iMonth)
iSpc = weekday(iyear & "-" & imonth & "-1")-1
if iCount + iSpc <= 35 then iNum = 35 else iNum = 42 end if
'       ┯                  ┯
' ┍──┴─────────┴──┓
' |          画出表格            |
' ┗───────────────┛
Document.write "<table width='210' height='20' border='0' cellpadding='0' cellspacing='1' bgcolor='#000000'>" & vbcrlf
Document.write "  <tr>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'><a href='" & iPrev & "' title='上月'><<</a></td>" & vbcrlf
Document.write "    <td height='20' colspan='5' align='center' valign='middle' bgcolor='#FFFFFF'>" & iYear & "年" & iMonth & "月" & "</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'><a href='" & iNext & "' title='下月'>>></a></td>" & vbcrlf
Document.write "  </tr>" & vbcrlf
Document.write "  <tr>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>日</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>一</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>二</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>三</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>四</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>五</td>" & vbcrlf
Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>六</td>" & vbcrlf
Document.write "  </tr>" & vbcrlf
For i=1 to iNum
	if i mod 7 = 1 then Document.write "  <tr>" & vbcrlf
	if i<=iSpc then
		Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'> </td>" & vbcrlf
	elseif i>iSpc + iCount then
		Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'> </td>" & vbcrlf
	else
		j = j + 1
		Document.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>" & j & "</td>" & vbcrlf
	end if
	if i mod 7 = 0 then  Document.write "  </tr>" & vbcrlf
Next
Document.write "</table>" & vbcrlf
</script>


二、ASP版

HTML
<%
'       ┯                  ┯
' ┍──┴─────────┴──┓
' |   【函数】                   |
' |    getCount:取得月总天数     |
' |    prevMonth:取得上月地址    |
' |    nextMonth:取得下月地址    |
' |    getPar:取得地址参数       |
' ┗───────────────┛
Function getCount(ByVal iYear,ByVal iMonth)
	Select Case iMonth
		Case 1, 3, 5, 7, 8, 10, 12
			getCount = 31
		Case 4, 6, 9, 11
			getCount = 30
		Case 2
			If IsDate(iyear & "-" & imonth & "-29") Then
				getCount = 29
			Else
				getCount = 28
			End If
	End Select
End Function
Function prevMonth(ByVal iYear,ByVal iMonth)
	Dim temp
	temp = dateadd("m",-1,iYear & "-" & iMonth & "-1")
	iYear = year(temp)
	iMonth = month(temp)
	prevMonth = "?iYear=" & iYear & "&iMonth=" & iMonth
End function
Function nextMonth(ByVal iYear,ByVal iMonth)
	Dim temp
	temp = dateadd("m",1,iYear & "-" & iMonth & "-1")
	iYear = year(temp)
	iMonth = month(temp)
	nextMonth = "?iYear=" & iYear & "&iMonth=" & iMonth
End function
Sub getPar()
	iYear = request.querystring("iyear")
	iMonth = request.querystring("iMonth")
	if isempty(iYear) then iYear = year(date())
	if isempty(iMonth) then iMonth = month(date())
End sub
'       ┯                  ┯
' ┍──┴─────────┴──┓
' |    【变量】                  |
' |     iPrev:上个月地址         |
' |     iNext:下个月地址         |
' |     iCount:月总天数          |
' |     iSpc:第一行空格数        |
' |     iNum:总单元格数35或42    |
' |     iYear:年份               |
' |     iMonth:月份              |
' ┗───────────────┛
Dim i,j,iPrev,iNext,iCount,iSpc,iNum,iYear,iMonth
Call getPar()
iCount = getCount(iYear,iMonth)
iPrev = prevMonth(iYear,iMonth)
iNext = nextMonth(iYear,iMonth)
iSpc = weekday(iyear & "-" & imonth & "-1")-1
if iCount + iSpc <= 35 then iNum = 35 else iNum = 42 end if
'       ┯                  ┯
' ┍──┴─────────┴──┓
' |          画出表格            |
' ┗───────────────┛
Response.write "<table width='210' height='20' border='0' cellpadding='0' cellspacing='1' bgcolor='#000000'>" & vbcrlf
Response.write "  <tr>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'><a href='" & iPrev & "' title='上月'><<</a></td>" & vbcrlf
Response.write "    <td height='20' colspan='5' align='center' valign='middle' bgcolor='#FFFFFF'>" & iYear & "年" & iMonth & "月" & "</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'><a href='" & iNext & "' title='下月'>>></a></td>" & vbcrlf
Response.write "  </tr>" & vbcrlf
Response.write "  <tr>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>日</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>一</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>二</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>三</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>四</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>五</td>" & vbcrlf
Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>六</td>" & vbcrlf
Response.write "  </tr>" & vbcrlf
For i=1 to iNum
	if i mod 7 = 1 then Response.write "  <tr>" & vbcrlf
	if i<=iSpc then
		Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'> </td>" & vbcrlf
	elseif i>iSpc + iCount then
		Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'> </td>" & vbcrlf
	else
		j = j + 1
		Response.write "    <td width='30' height='20' align='center' valign='middle' bgcolor='#FFFFFF'>" & j & "</td>" & vbcrlf
	end if
	if i mod 7 = 0 then  Response.write "  </tr>" & vbcrlf
Next
Response.write "</table>" & vbcrlf
%>

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 判断某月份总天数 下一篇 → 静态页面也玩参数