亮显示当天,能够选取某天显示,并能够加入事件。
<%
*******************************************************
* asp 101 sample code – http://www.asp101.com *
* *
* this code is made available as a service to our *
* visitors and is provided strictly for the *
* purpose of illustration. *
* *
* please direct all inquiries to webmaster@asp101.com *
*******************************************************
%>
<%
***begin function declaration***
new and improved getdaysinmonth implementation.
thanks to florent renucci for pointing out that i
could easily use the same method i used for the
revised getweekdaymonthstartson function.
function getdaysinmonth(imonth, iyear)
dim dtemp
dtemp = dateadd("d", -1, dateserial(iyear, imonth + 1, 1))
getdaysinmonth = day(dtemp)
end function
previous implementation on getdaysinmonth
function getdaysinmonth(imonth, iyear)
select case imonth
case 1, 3, 5, 7, 8, 10, 12
getdaysinmonth = 31
case 4, 6, 9, 11
getdaysinmonth = 30
case 2
if isdate("february 29, " & iyear) then
getdaysinmonth = 29
else
getdaysinmonth = 28
end if
end select
end function
function getweekdaymonthstartson(danydayinthemonth)
dim dtemp
dtemp = dateadd("d", -(day(danydayinthemonth) – 1), danydayinthemonth)
getweekdaymonthstartson = weekday(dtemp)
end function
function subtractonemonth(ddate)
subtractonemonth = dateadd("m", -1, ddate)
end function
function addonemonth(ddate)
addonemonth = dateadd("m", 1, ddate)
end function
***end function declaration***
dim ddate date were displaying calendar for
dim idim days in month
dim idow day of week that month starts on
dim icurrent variable we use to hold current day of month as we write table
dim iposition variable we use to hold current position in table
get selected date. there are two ways to do this.
first check if we were passed a full date in rqs("date").
if so use it, if not look for seperate variables, putting them togeter into a date.
lastly check if the date is valid…if not use today
if isdate(request.querystring("date")) then
ddate = cdate(request.querystring("date"))
else
if isdate(request.querystring("month") & "-" & request.querystring("day") & "-" &
request.querystring("year")) then
ddate = cdate(request.querystring("month") & "-" & request.querystring("day") & "-"
& request.querystring("year"))
else
ddate = date()
the annoyingly bad solution for those of you running iis3
if len(request.querystring("month")) <> 0 or len(request.querystring("day")) <> 0 or
len(request.querystring("year")) <> 0 or len(request.querystring("date")) <> 0 then
response.write "the date you picked was not a valid date. the calendar
was set to todays date.<br><br>"
end if
the elegant solution for those of you running iis4
if request.querystring.count <> 0 then response.write "the date you picked was not
a valid date. the calendar was set to todays date.<br><br>"
end if
end if
now weve got the date. now get days in the choosen month and the day of the week it starts on.
idim = getdaysinmonth(month(ddate), year(ddate))
idow = getweekdaymonthstartson(ddate)
%>
<!– outer table is simply to get the pretty border–>
<table border=10 cellspacing=0 cellpadding=0>
<tr>
<td>
<table border=1 cellspacing=0 cellpadding=1 bgcolor=#99ccff>
<tr>
<td bgcolor=#000099 align="center" colspan=7>
<table width=100% border=0 cellspacing=0 cellpadding=0>
<tr>
<td align="right"><a href="./calendar.asp?date=<%=
subtractonemonth(ddate) %>"><font color=#ffff00 size="-1"><<</font></a></td>
<td align="center"><font color=#ffff00><b><%=
monthname(month(ddate)) & " " & year(ddate) %></b></font></td>
<td align="left"><a href="./calendar.asp?date=<%=
addonemonth(ddate) %>"><font color=#ffff00 size="-1">>></font></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>sun</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>mon</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>tue</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>wed</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>thu</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>fri</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
<td align="center" bgcolor=#0000cc><font color=#ffff00><b>sat</b></font><br><img
src="./images/spacer.gif" width=60 height=1 border=0></td>
</tr>
<%
write spacer cells at beginning of first row if month doesnt start on a sunday.
if idow <> 1 then
response.write vbtab & "<tr>" & vbcrlf
iposition = 1
do while iposition < idow
response.write vbtab & vbtab & "<td> </td>" & vbcrlf
iposition = iposition + 1
loop
end if
write days of month in proper day slots
icurrent = 1
iposition = idow
do while icurrent <= idim
if were at the begginning of a row then write tr
if iposition = 1 then
response.write vbtab & "<tr>" & vbcrlf
end if
if the day were writing is the selected day then highlight it somehow.
if icurrent = day(ddate) then
response.write vbtab & vbtab & "<td bgcolor=#00ffff><font size=""-1""><b>" &
icurrent & "</b></font><br><br></td>" & vbcrlf
else
response.write vbtab & vbtab & "<td><a href=""./calendar.asp?date=" & month(ddate)
& "-" & icurrent & "-" & year(ddate) & """><font size=""-1"">" & icurrent & "</font></a><br><br></td>" &
vbcrlf
end if
if were at the endof a row then write /tr
if iposition = 7 then
response.write vbtab & "</tr>" & vbcrlf
iposition = 0
end if
increment variables
icurrent = icurrent + 1
iposition = iposition + 1
loop
write spacer cells at end of last row if month doesnt end on a saturday.
if iposition <> 1 then
do while iposition <= 7
response.write vbtab & vbtab & "<td> </td>" & vbcrlf
iposition = iposition + 1
loop
response.write vbtab & "</tr>" & vbcrlf
end if
%>
</table>
</td>
</tr>
</table>
<br>
<table border=0 cellspacing=0 cellpadding=0><tr><td align="center">
<form action="./calendar.asp" method=get>
<select name="month">
<option value=1>january</option>
<option value=2>february</option>
<option value=3>march</option>
<option value=4>april</option>
<option value=5>may</option>
<option value=6>june</option>
<option value=7>july</option>
<option value=8>august</option>
<option value=9>september</option>
<option value=10>october</option>
<option value=11>november</option>
<option value=12>december</option>
</select>
<select name="day">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
<option value=11>11</option>
<option value=12>12</option>
<option value=13>13</option>
<option value=14>14</option>
<option value=15>15</option>
<option value=16>16</option>
<option value=17>17</option>
<option value=18>18</option>
<option value=19>19</option>
<option value=20>20</option>
<option value=21>21</option>
<option value=22>22</option>
<option value=23>23</option>
<option value=24>24</option>
<option value=25>25</option>
<option value=26>26</option>
<option value=27>27</option>
<option value=28>28</option>
<option value=29>29</option>
<option value=30>30</option>
<option value=31>31</option>
</select>
<select name="year">
<option value=1990>1990</option>
<option value=1991>1991</option>
<option value=1992>1992</option>
<option value=1993>1993</option>
<option value=1994>1994</option>
<option value=1995>1995</option>
<option value=1996>1996</option>
<option value=1997>1997</option>
<option value=1998>1998</option>
<option value=1999>1999</option>
<option value=2000 selected>2000</option>
<option value=2001>2001</option>
<option value=2002>2002</option>
<option value=2003>2003</option>
<option value=2004>2004</option>
<option value=2005>2005</option>
<option value=2006>2006</option>
<option value=2007>2007</option>
<option value=2008>2008</option>
<option value=2009>2009</option>
<option value=2010>2010</option>
</select>
<br>
<input type="submit" value="show this date on the calendar!">
</form>
</td></tr></table>
