欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP实现的日历代码实例程序】,下面是详细的分享!
ASP实现的日历代码实例程序
<style>
td { font-family: "宋体"; font-size:9pt}
</style>
<body bgcolor="eeeeee">
<table width="180" cellpadding="0" cellspacing="1" bgcolor="dddddd" align=center>
<%
'以下为ASP中通过该日历算法实现的具体代码
'先判断是否指定了一个年份和月份,没有则根据当前的年和月份显示
If Request("ReqDate")="" then
CurrentDate=Date
else
CurrentDate=Trim(Request("ReqDate"))
end if
pyear=year(CurrentDate)
pmonth=month(CurrentDate)
'以下的代码生成日历显示的表格头内容
%>
<tr align="LEFT" bgcolor="#dddddd">
<td width="14%" height="19" align="center">
<input type="button" value="<<" onclick="JavaScript:location.href='http://www.chinaz.com/program/2007/1207/?ReqDate=<%=DateAdd("m",-1,CurrentDate) %>'">
</td>
<td colspan="5" align="center">
<%=pyear%>年<%=pmonth%>月
</td>
<td width="14%" align="center">
<input type="button" value=">>" onclick="JavaScript:location.href='http://www.chinaz.com/program/2007/1207/?ReqDate=<%=DateAdd("m",1,CurrentDate)%>'">
</td>
</tr>
<tr align="center" bgcolor="#CCCCCC">
<td width="14%" height="19"> 日</td>
<td width="14%"> 一</td>
<td width="14%"> 二</td>
<td width="14%"> 三</td>
<td width="14%"> 四</td>
<td width="14%"> 五</td>
<td width="14%"> 六</td>
</tr>
<tr align=center bgcolor=ffffff height=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天)
if nunmonthstart+nunmonthend<36 then
maxi=36
else
maxi=43
end if
'循环生成表格并显示
i=1
do while i<maxi
iv=i-nunmonthstart
if i>nunmonthstart and i<=nunmonthend+nunmonthstart then
'如果为显示的是今天则用红色背景显示
if iv=Day(now) and month(now)=pmonth and year(now)=pyear then
response.write( "<td align=center bgcolor=ffaaaa><a href='http://www.chinaz.com/program/2007/1207/20666.shtml#' target=_blank>" & iv & "</a></td>")
else
response.write( "<td align=center><a href='http://www.chinaz.com/program/2007/1207/20666.shtml#' target=_blank>" & iv & "</a></td>")
end if
else
response.write( "<td> </td>")
end if
'如果能被7整除(每行显示7个)则输出一个换行
if i mod 7=0 then
response.write( "</tr><tr align=center bgcolor=ffffff height=19>")
end if
i=i+1
loop
%>
</table>
</body>
以上所分享的是关于ASP实现的日历代码实例程序,下面是编辑为你推荐的有价值的用户互动:
相关问题:用asp做的程序中直接引用日历控件如何实现
答:百度搜索一下“input js选择日期的控件” >>详细
相关问题:asp.net 引用JS作的日历控件,最好能给个实例,简...
答:首先,导入js日历控件; 其次,注册你asp.net控件想要引用js控件的事件,比如:asp.net textbox控件,你想在textbox获取焦点时,击发并弹出js日历控件,则须做以下操作:textbox.Attributes.Add("事件名称", "调用js日历控件方法") >>详细
相关问题:ASP.NET中显示日历控件的代码
答:1.在.aspx文件中手写代码: 2.鼠标点击你想要放置日历控件的页面,鼠标放到左侧的工具箱上,按住鼠标左键将日历空间拖拽到页面上即可 以上两种方法实现的效果是一样的,选其中的一个即可。 >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
