怎样用vbscript 写个日历
怎样用vbscript 写个日历 ,我要代码加注释。
2010-06-15 00:41
程序代码:<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<%
y=request.querystring("y")
m=request.querystring("m")
d=request.querystring("d")
if y="" then
y=year(date)
m=month(date)
d=day(date)
end if
call blogdate(y,m,d)
'=====================以年月日为参数的显示==============================================
sub blogdate(y,m,d) '
str1=" 当前的日期是"&y&"年"&m&"月"&d&"日 " '得到当前日期的年月日
nowdate=y&"-"&m&"-"&d
lastdate=dateadd("m",-1,nowdate)
lasty=year(lastdate)
lastm=month(lastdate)
nextdate=dateadd("m",1,nowdate)
nexty=year(nextdate)
nextm=month(nextdate)
str1=str1&"<a href="&request.servervariables("path_info")&"?y="&lasty&"&m="&lastm&"&d=1"&">上一月</a> "
str1=str1&"<a href="&request.servervariables("path_info")&"?y="&nexty&"&m="&nextm&"&d=1"&">下一月</a> "
str1=str1&"<a href="&request.servervariables("path_info")&">返回今日</a>"
response.write str1
thismonth=y&"-"&m&"-1" '当前月的第一天
nextmonth=dateadd("m",1,thismonth) '下个月的第一天
num=datediff("d",thismonth,nextmonth) '当前月的天数
firstday=weekday(thismonth)-1 '得到当前月第一天的星期
'call displaydate(firstday,num)
Response.Write "<table border=1 width=""40%"" style=""border-collapse:collapse"">" & vbCrlf
Response.Write "<tr>" & vbCrlf
Response.Write "<td align=""center"">星期日</td>" & vbCrlf
Response.Write "<td align=""center"">星期一</td>" & vbCrlf
Response.Write "<td align=""center"">星期二</td>" & vbCrlf
Response.Write "<td align=""center"">星期三</td>" & vbCrlf
Response.Write "<td align=""center"">星期四</td>" & vbCrlf
Response.Write "<td align=""center"">星期五</td>" & vbCrlf
Response.Write "<td align=""center"">星期六</td>" & vbCrlf
Response.Write "</tr>" & vbCrlf
'需要参数:当前月第一天的星期firstday,当前月的天数 num
for n=1 to 6
response.write "<tr>"
for i=1 to 7
thisday=0
if i>firstday then thisday=i-firstday
if n>1 then thisday=7*(n-1)+i-firstday
if thisday>num then thisday=0
if thisday=0 then
display=" "
else
display="<a href="&request.servervariables("path_info")&"?y="&y&"&m="&m&"&d="&thisday&">"&thisday&"</a>"
end if
response.write "<td align=""center"">"&display&"</td>"
next
if n=5 and (thisday=num or thisday=0) then n=n+1
response.write "</tr>"
next
Response.Write "</table>" & vbCrlf
end sub
'===================================================================
%>
2010-06-18 15:48
程序代码:<!--
自制 vbscript 日歷
可以點擊頂端的“年”,“月”以及
“ <<” “>> ”進行日期選取 “
-->
<html>
<head>
<style>
.Weekend{color:red; font-family:Verdana,Arial,Helvetica,sans-serif; text-align:center; cursor:hand; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
.Today{background-color:#cccccc; color:#006666; font-family:Verdana,Arial,Helvetica,sans-serif; font-weight:bold; text-align:center; cursor:hand; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
.Day{color:#006666; font-family:Verdana,Arial,Helvetica,sans-serif; text-align:center; cursor:hand; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
.Date{text-align:center; color:#006666; font-family:Verdana,Arial,Helvetica,sans-serif; background-color:#cccccc; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
.OtherMonth{text-align:center; font-family:Verdana,Arial,Helvetica,sans-serif; border-left:solid 1px #c0c0c0; border-right:solid 1px #c0c0c0; border-top:solid 1px #c0c0c0; border-bottom:solid 1px #c0c0c0;}
.YearMonth{font-weight:normal; color:#006666; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
.YearMonthOver{font-weight:normal; color:#000000; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
.Month{font-weight:normal; height:30px; text-align:center; color:#006666; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
.MonthOver{font-weight:normal; height:30px; text-align:center; color:#000000; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
.Year{font-weight:normal; height:20px; text-align:center; color:#006666; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
.YearOver{font-weight:normal; height:20px; text-align:center; color:#000000; cursor:hand; font-family: Verdana,Arial,Helvetica,sans-serif;}
.PrevNext{cursor:hand; color:#006666;}
.PrevNextOver{cursor:hand; color:#000000; font-weight:bold;}
.Bottom{cursor:hand; color:#006666; font-size:10pt; text-align:center; font-family:Verdana,Arial,Helvetica,sans-serif;}
.BottomOver{cursor:hand; color:#000000; font-size:10pt; text-align:center; font-family:Verdana,Arial,Helvetica,sans-serif;}
</style>
</head>
<body>
<input type="text" style="font-family: Verdana, Arial, Helvetica, sans-serif;" onclick="OpenCalendar(this)">
</body>
</html>
<script language="vbscript" type="text/vbscript">
<!--
document.write "<div id='divCalendar' style='background-color:#ccffff; text-align:center; position:absolute; z-index:1; width:160px; border:solid 1px gray; font-size:10pt; display:none;'></div>"
dim AryCalendarDay(41)
dim strCalendarDate, strCalendarYear, strCalendarMonth, strCalendarDay
dim objCalendarText, divCalendarLeft, divCalendarTop
dim AryWeekDays
dim strCalendarType
AryWeekDays = Array("日", "一", "二", "三", "四", "五", "六")
strCalendarType = "D"
function CreateCalendar()
dim strHtml
strHtml = ""
strHtml = strHtml & "<table cellpadding='0' cellspacing='0' border='0' style='width:100%; border-bottom:solid 1px #cccccc; color:#006666;'><tr>"
strHtml = strHtml & "<td class='PrevNext' language='javascript' onmouseover='this.className=""PrevNextOver""' onmouseout='this.className=""PrevNext""' style='width:15%; text-align:left;' onclick='PrevMonth()'><<</td>"
strHtml = strHtml & "<td class='YearMonth' language='javascript' onmouseover='this.className=""YearMonthOver""' onmouseout='this.className=""YearMonth""' onclick='YearClick()'>" & strCalendarYear & "</td>"
strHtml = strHtml & "<td style='width:15%;'>年</td>"
strHtml = strHtml & "<td class='YearMonth' language='javascript' onmouseover='this.className=""YearMonthOver""' onmouseout='this.className=""YearMonth""' onclick='MonthClick()'>" & strCalendarMonth & "</td>"
strHtml = strHtml & "<td style='width:15%;'>月</td>"
strHtml = strHtml & "<td class='PrevNext' language='javascript' onmouseover='this.className=""PrevNextOver""' onmouseout='this.className=""PrevNext""' style='width:15%; text-align:right;' onclick='NextMonth()'>>></td>"
strHtml = strHtml & "</tr></table>"
strHtml = strHtml & "<div id='divCalendarContent' style='text-align:center;'></div>"
strHtml = strHtml & "<table border='0' cellpadding='0' cellspacing='0'>"
strHtml = strHtml & "<col width='60%'><col width='10%'><col width='30%'>"
strHtml = strHtml & "<tr><td colspan='2' style='height:2px;'/></tr><tr>"
strHtml = strHtml & "<td class='Bottom' language='javascript' onmouseover='this.className=""BottomOver""' onmouseout='this.className=""Bottom""' onclick='GetDate1()'>" & strCalendarDate & "</td>"
strHtml = strHtml & "<td></td>"
strHtml = strHtml & "<td class='Bottom' language='javascript' onmouseover='this.className=""BottomOver""' onmouseout='this.className=""Bottom""' onclick='Clean()'>Clean</td>"
strHtml = strHtml & "</tr><tr><td colspan='2' style='height:2px;'/></tr></table>"
document.all.divCalendar.innerHTML = strHtml
select case strCalendarType
case "Y"
document.all.divCalendarContent.innerHTML = SetYear
case "M"
document.all.divCalendarContent.innerHTML = SetMonth
case else
document.all.divCalendarContent.innerHTML = SetDay
end select
divCalendar.style.left = divCalendarLeft
divCalendar.style.top = divCalendarTop + 20
divCalendar.style.display = ""
end function
function SetYear()
dim strHtml, intI
strHtml = "<table cellpadding='0' cellspacing='0' style='width:90%; font-size:10pt;'>"
strHtml = strHtml & "<tr><td style='height:10px;'></td></tr>"
for intI=0 to 19
if intI mod 4 = 0 then
strHtml = strHtml & "<tr>"
end if
if (cint(strCalendarYear)+intI-10) = strCalendarYear then
strHtml = strHtml & "<td class='Year' language='javascript' onmouseover='this.className=""YearOver""' onmouseout='this.className=""Year""' onclick='SelectYear()' style='color:red;'>" & cint(strCalendarYear)+intI-10 & "</td>"
else
strHtml = strHtml & "<td class='Year' language='javascript' onmouseover='this.className=""YearOver""' onmouseout='this.className=""Year""' onclick='SelectYear()'>" & cint(strCalendarYear)+intI-10 & "</td>"
end if
if intI mod 4 = 3 then
strHtml = strHtml & "</tr>"
end if
next
strHtml = strHtml & "</table>"
SetYear = strHtml
end function
function SetMonth()
dim strHtml, intI
strHtml = "<table cellpadding='0' cellspacing='0'style='width:90%; font-size:10pt;'>"
strHtml = strHtml & "<tr><td style='height:10px;'></td></tr>"
for intI=0 to 11
if intI mod 4 = 0 then
strHtml = strHtml & "<tr>"
end if
if right("0"&(cint(intI)+1),2) = strCalendarMonth then
strHtml = strHtml & "<td class='Month' language='javascript' onmouseover='this.className=""MonthOver""' onmouseout='this.className=""Month""' onclick='SelectMonth()' style='color:red;'>" & right("0"&(cint(intI)+1),2) & "</td>"
else
strHtml = strHtml & "<td class='Month' language='javascript' onmouseover='this.className=""MonthOver""' onmouseout='this.className=""Month""' onclick='SelectMonth()'>" & right("0"&(cint(intI)+1),2) & "</td>"
end if
if intI mod 4 = 3 then
strHtml = strHtml & "</tr>"
end if
next
strHtml = strHtml & "</table>"
SetMonth = strHtml
end function
function SetDay()
dim intEndDay, intI, intEnd
dim strHtml
intEndDay = dateadd("m", 1, cdate(strCalendarYear & "/" & strCalendarMonth & "/01"))
intEndDay = dateadd("d", -1, cdate(intEndDay))
intEndDay = Day(cdate(intEndDay))
dim intDateFirst
intDateFirst = weekday(cdate(strCalendarYear & "/" & strCalendarMonth & "/01"),vbSunday)
if (cint(intDateFirst)+cint(intEndDay)) > 36 then
intEnd = 41
else
intEnd = 34
end if
for intI=0 to intEnd
if intI < intDateFirst - 1 then
AryCalendarDay(intI) = 0
elseif intI >= intEndDay + intDateFirst - 1 then
AryCalendarDay(intI) = 0
else
AryCalendarDay(intI) = intI - intDateFirst + 2
end if
next
strHtml = strHtml & "<table border='0' style='width:160px; font-size:10pt;' cellpadding='0' cellspacing='0'>"
strHtml = strHtml & "<col width='15%'><col width='14%'><col width='14%'><col width='14%'><col width='14%'><col width='14%'><col width='15%'>"
strHtml = strHtml & "<tr>"
for intI=0 to 6
strHtml = strHtml & "<td class='Date'>" & AryWeekDays(intI) & "</td>"
next
strHtml = strHtml & "</tr>"
for intI=0 to intEnd
if intI mod 7 = 0 then
strHtml = strHtml & "<tr>"
end if
if AryCalendarDay(intI) <> "0" then
if right("0"&AryCalendarDay(intI),2) = strCalendarDay then
strHtml = strHtml & "<td class='Today' onclick='GetDate()'>" & AryCalendarDay(intI) & "</td>"
elseif intI mod 7 = 0 or intI mod 7 = 6 then
strHtml = strHtml & "<td class='Weekend' onclick='GetDate()'>" & AryCalendarDay(intI) & "</td>"
else
strHtml = strHtml & "<td class='Day' onclick='GetDate()'>" & AryCalendarDay(intI) & "</td>"
end if
else
strHtml = strHtml & "<td class='OtherMonth'> </td>"
end if
if intI mod 7 = 6 then
strHtml = strHtml & "</tr>"
end if
next
strHtml = strHtml & "</table>"
SetDay = strHtml
end Function
function GetDate()
strCalendarDay = window.event.srcElement.innerText
strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
objCalendarText.value = strCalendarDate
divCalendar.style.display = "none"
end function
function GetDate1()
strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
objCalendarText.value = strCalendarDate
divCalendar.style.display = "none"
end function
function OpenCalendar(objThis)
set objCalendarText = objThis
divCalendarLeft = objCalendarText.offsetLeft
divCalendarTop = objCalendarText.offsetTop
while not objCalendarText.offsetParent is nothing
set objCalendarText = objCalendarText.offsetParent
divCalendarLeft = divCalendarLeft + objCalendarText.offsetLeft
divCalendarTop = divCalendarTop + objCalendarText.offsetTop
wend
set objCalendarText = objThis
if isDate(objCalendarText.value) then
strCalendarDate = Year(cdate(objCalendarText.value)) & "/" & right("0"&Month(cdate(objCalendarText.value)),2) & "/" & right("0"&Day(cdate(objCalendarText.value)),2)
else
strCalendarDate = Year(Now) & "/" & right("0"&Month(Now),2) & "/" & right("0"&Day(Now),2)
end if
strCalendarYear = Year(strCalendarDate)
strCalendarMonth = right("0" & Month(strCalendarDate), 2)
strCalendarDay = right("0" & Day(strCalendarDate), 2)
call SetValue()
end function
function SetValue()
while not isDate(strCalendarDate)
strCalendarDay = cint(strCalendarDay) - 1
strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
wend
strCalendarYear = Year(strCalendarDate)
strCalendarMonth = right("0" & Month(strCalendarDate), 2)
strCalendarDay = right("0" & Day(strCalendarDate), 2)
call CreateCalendar()
end function
function YearClick()
strCalendarType = "Y"
call SetValue()
end function
function MonthClick()
strCalendarType = "M"
call SetValue()
end function
function SelectMonth()
strCalendarMonth = window.event.srcElement.innerText
strCalendarType = "D"
strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
call SetValue()
end function
function SelectYear()
strCalendarYear = window.event.srcElement.innerText
strCalendarType = "D"
strCalendarDate = strCalendarYear & "/" & right("0"&strCalendarMonth, 2) & "/" & right("0"&strCalendarDay, 2)
call SetValue()
end function
function PrevMonth()
strCalendarDate = dateadd("m", -1, cdate(strCalendarDate))
strCalendarType = "D"
call SetValue()
end function
function NextMonth()
strCalendarDate = dateadd("m", 1, cdate(strCalendarDate))
strCalendarType = "D"
call SetValue()
end function
function Clean()
objCalendarText.value = ""
divCalendar.style.display = "none"
end function
-->
</script>
2010-06-18 16:00