一个asp日历

这是在做项目的过程中写的,贴出来共享一下。可以结合数据库,实现点击某一天,显示某些内容的功能,给大家做个参考也好。以前的日期用蓝色表示,当天用红色,以后的日期用默认。下面是源码:

<html>
<head>
<link href="../css.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<%
Dim dtToday
dtToday = Date()

Dim dtCurViewMonth ' First day of the currently viewed month
Dim dtCurViewDay ' Current day of the currently viewed month
Dim frmDate ' Date submitted by form

' if the GO button was used, build the date from the month and year

If InStr(1, Request.Form, "subGO", 1) > 0  then
 if Request.Form("CURDATE_month") = "" then
  tmpMonth = month(now())
 else
  tmpMonth = Request.Form("CURDATE_month")
 End If
 
 if Request.Form("CURDATE_year") = "" then
  tmpyear = year(now())
 else
  tmpyear = Request.Form("CURDATE_year")
 End If
  
 tmpDate = "1 " & tmpMonth & " 1999"
 
 mnth = Month(tmpDate)
 frmDate = DateSerial(tmpyear, mnth, 1)
Else

 frmDate = Request.Form("CURDATE")
 
end if
   If InStr(1, Request.Form, "subPrev", 1) > 0 Then
      dtCurViewMonth = DateAdd("m", -1, Request.Form("CURDATE"))
' if next button was hit on the form
   ElseIf InStr(1, Request.Form, "subNext", 1) > 0 Then
      dtCurViewMonth = DateAdd("m", 1, Request.Form("CURDATE"))
' anyother time
      Else
        If InStr(1, Request.Form, "subGO", 1) > 0 then
   dtCurViewMonth = frmDate
   Else
   if Request("view_date") <> "" then
    dtCurviewMonth = frmDate
   else
            dtCurViewMonth = DateSerial(Year(dtToday), Month(dtToday), 1)
            End If
         End If
   End If

%>
<table style="border-collapse:collapse" width="200" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
  <tr>
    <td width="100%">
<DIV align=center>
<FORM NAME="fmNextPrev" ACTION="calendar.asp" METHOD=POST>
 <TABLE WIDTH="100%" BORDER=0 CELLPADDING=1 CELLSPACING=0 >
 <TR bgcolor="#E8E8E8" VALIGN=MIDDLE ALIGN=CENTER>
   <TD COLSPAN=7>
  <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%" BORDER=0>
   <TR bgcolor="#999999" VALIGN=MIDDLE ALIGN=CENTER>
    <TD WIDTH="30%" ALIGN=RIGHT><input name="subPrev" type=submit class="kuang" value="上月"></TD>
    <TD WIDTH="40%" class="12th"><b class="white"><%= Year(dtCurViewMonth)& "-" & Month(dtCurViewMonth)%></B></TD>
    <TD WIDTH="26%" ALIGN=LEFT> <INPUT NAME="subNext" TYPE=submit class="kuang" value="下月"></TD>
   </TR>
  </TABLE>
  
   </TD>
 </TR>
 <TR VALIGN=TOP ALIGN=CENTER BGCOLOR="#efefef">
 <%
 iday = Array( "日", "一", "二", "三","四","五","六")
 For i = 0 To UBound(iday)
  %>
  <TH WIDTH="30" height="0"  bgcolor="#e8e8e8" class="12th" ><%=iday(i)%></TH>
  <%
 Next
 %>
 </TR>
      <%
 dtCurViewDay = DtPrevSunday(dtCurViewMonth)
 
 For iWeek = 0 To 5
  Response.Write "<TR  bgcolor=#FFFFFF class=12th>" & vbCrLf
  For iDay = 0 To 6
   bbb="#"&Year(dtCurViewMonth)&"-"&Month(dtCurViewMonth)&"-"&Day(dtCurViewDay)&"#"
   tempdate = "#"&date&"#"
   if bbb=tempdate then
     abc = Day(dtCurViewDay)
    if (Month(dtCurViewDay) = Month(Now())) then
     Response.Write "<TD ALIGN=CENTER bgcolor=#e8e8e8>"
    else
     Response.Write "<TD ALIGN=CENTER>"
    end if
   else
    Response.Write "<TD ALIGN=CENTER>"
   end if
   If Month(dtCurViewDay) = Month(dtCurViewMonth) Then
    If dtCurViewDay = dtToday Then
     fontColor = "#660000"
    Else
     fontColor = "#996666"
    End If
         '---- Write day of month
'    rs.MoveFirst 
'    While Not rs.EOF ' 判断是否过了最后一项
     aaa=dtCurViewDay
     bbb=date()
     if bbb<aaa then
      Response.Write "<div class=12th>"&Day(dtCurViewDay)&"</div>"
     elseif bbb=aaa then
      Response.Write "<font color='red'>"&Day(dtCurViewDay)&"</font>"
     else
      Response.Write "<font color='blue'>"&Day(dtCurViewDay)&"</font>"
     end if
'     rs.MoveNext ' 移到下一项
'    Wend 
   end if
   Response.Write "</TD>" & vbCrLf
   dtCurViewDay = DateAdd("d", 1, dtCurViewDay)
  Next
  Response.Write "</TR>" & vbCrLf
 Next
%>
      <%REM --------END OF DRAW CALENDAR SECTION-------- %>
    </TABLE><input type="hidden" Name="CURDATE" Value="<%=dtCurViewMonth%>">
<%    
'conn.close
'set rs=nothing
'--------------------------------------------------
   Function DtPrevSunday(ByVal dt)
      Do While WeekDay(dt) > vbSunday
         dt = DateAdd("d", -1, dt)
      Loop
      DtPrevSunday = dt
   End Function
'--------------------------------------------------
%>
 </FORM>
</DIV></td>
  </tr>
</table>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值