手机
当前位置:查字典教程网 >编程开发 >ASP教程 >ASP中通过该日历算法实现的具体代码
ASP中通过该日历算法实现的具体代码
摘要:复制代码代码如下:td{font-family:"宋体";font-size:9pt}

复制代码 代码如下:

<style>

td{font-family:"宋体";font-size:9pt}

</style>

<bodybgcolor="eeeeee">

<tablewidth="180"cellpadding="0"cellspacing="1"bgcolor="dddddd"align=center>

<%

'以下为ASP中通过该日历算法实现的具体代码

'先判断是否指定了一个年份和月份,没有则根据当前的年和月份显示

IfRequest("ReqDate")=""then

CurrentDate=Date

else

CurrentDate=Trim(Request("ReqDate"))

endif

pyear=year(CurrentDate)

pmonth=month(CurrentDate)

'以下的代码生成日历显示的表格头内容

%>

<tralign="LEFT"bgcolor="#dddddd">

<tdwidth="14%"height="19"align="center">

<inputtype="button"value="<<"onclick="JavaScript:location.href='?ReqDate=<%=DateAdd("m",-1,CurrentDate)%>'">

</td>

<tdcolspan="5"align="center">

<%=pyear%>年<%=pmonth%>月

</td>

<tdwidth="14%"align="center">

<inputtype="button"value=">>"onclick="JavaScript:location.href='?ReqDate=<%=DateAdd("m",1,CurrentDate)%>'">

</td>

</tr>

<tralign="center"bgcolor="#CCCCCC">

<tdwidth="14%"height="19">日</td>

<tdwidth="14%">一</td>

<tdwidth="14%">二</td>

<tdwidth="14%">三</td>

<tdwidth="14%">四</td>

<tdwidth="14%">五</td>

<tdwidth="14%">六</td>

</tr>

<tralign=centerbgcolor=ffffffheight=19>

<%

'由于ASP中没有获取指定月共有多少天的函数,因此我们需要通过其他算法来获得,算法其实很简单,就是计算一下要显示月份的1日至下个月的1日一共相差几天

fromDate=FormatDateTime(month(CurrentDate)&"/1/"&year(CurrentDate))

toDate=FormatDateTime(DateAdd("m",1,fromDate))

'获得要显示月份的第一天为周几

nunmonthstart=weekday(fromDate)-1

'获得要显示的1日至下个月的1日一共相差几天(月份一共有多少天)

nunmonthend=DateDiff("d",fromDate,toDate)

'判断显示日历需要用几行表格来显示(每行显示7天)

ifnunmonthstart+nunmonthend<36then

maxi=36

else

maxi=43

endif

'循环生成表格并显示

i=1

dowhilei<maxi

iv=i-nunmonthstart

ifi>nunmonthstartandi<=nunmonthend+nunmonthstartthen

'如果为显示的是今天则用红色背景显示

ifiv=Day(now)andmonth(now)=pmonthandyear(now)=pyearthen

response.write("<tdalign=centerbgcolor=#ffaaaa><ahref='#'target=_blank>"&iv&"</a></td>")

else

response.write("<tdalign=center><ahref='#'target=_blank>"&iv&"</a></td>")

endif

else

response.write("<td></td>")

endif

'如果能被7整除(每行显示7个)则输出一个换行

ifimod7=0then

response.write("</tr><tralign=centerbgcolor=ffffffheight=19>")

endif

i=i+1

loop

%>

</table>

</body></html>

【ASP中通过该日历算法实现的具体代码】相关文章:

DreamWeaver编写ASP时如何修改代码?

用正则和xmlHttp实现的asp小偷程序

FSO一些代码

用asp实现的代码批量修改程序,fso相关

ASP中MsgBox函数和InputBox函数的使用

asp FSO 读写文件本文件实现代码

通过ASP自动解压RAR文件

用asp实现检测文件编码

ASP读取IIS日志的小程序代码

ASP部分代码介绍

精品推荐
分类导航