日历代码

前两天看了一个比较好用的日历代码,记下来:

1<style> 
2td { font-family: "宋体"; font-size:9pt} 
3</style> 
4<body bgcolor="eeeeee"> 
5<table width="180" cellpadding="0" cellspacing="1" bgcolor="dddddd" align=center> 
6<? 
7//以下为PHP中通过该日历算法实现的具体代码 

9     //先判断是否指定了一个年份和月份,没有则根据当前的年和月份显示 
10     if($ReqDate==""){ 
11         $pyear=date("Y"); 
12         $pmonth=date("m"); 
13         $CurrentDate=date("Y-m-j"); 
14     }else{ 
15         $ReqDateStrs = explode("-",$ReqDate ); 
16         $pyear=$ReqDateStrs[0]; 
17         $pmonth=$ReqDateStrs[1]; 
18         $CurrentDate=$ReqDate; 
19     } 
20 
21//以下的代码生成日历显示的表格头内容 
22?> 
23<tr align="center" bgcolor="#dddddd"> 
24     <td width="14%" height="19" align="center"> 
25         <input type="button" value="<<" οnclick=" javascript :location.href='?ReqDate=<? echo date("Y-m-j",mktime(0,0,0,$pmonth-1,1,$pyear)); ?>'"> 
26     </td> 
27     <td colspan="5" align="center"> 
28         <? echo $CurrentDate; ?> 
29     </td> 
30     <td width="14%" align="center"> 
31         <input type="button" value=">>" οnclick=" javascript :location.href='?ReqDate=<? echo date("Y-m-j",mktime(0,0,0,$pmonth+1,1,$pyear)); ?>'"> 
32     </td> 
33   </tr> 
34   <tr align="center" bgcolor="#CCCCCC"> 
35     <td width="14%" height="19"> 日</td> 
36     <td width="14%"> 一</td> 
37     <td width="14%"> 二</td> 
38     <td width="14%"> 三</td> 
39     <td width="14%"> 四</td> 
40     <td width="14%"> 五</td> 
41     <td width="14%"> 六</td> 
42   </tr> 
43   <tr align=center bgcolor=ffffff height=19> 
44<? 
45     //获得要显示月份的第一天为周几 
46     $nunmonthstart=date('w',mktime(0,0,0,$pmonth,1,$pyear)); 
47     //获得要显示月份一共有多少天 
48     $nunmonthend=date('t',mktime(0,0,0,$pmonth,1,$pyear)); 
49     //判断显示日历需要用几行表格来显示(每行显示7天) 
50     if($nunmonthstart+$nunmonthend<36){ 
51         $maxi=36; 
52     } 
53     else{ 
54          $maxi=43; 
55      } 
56     //循环生成表格并显示 
57     for( $i=1; $i <$maxi; $i++) 
58      { 
59          $iv=$i-$nunmonthstart; 
60          if($i>$nunmonthstart && $i<=$nunmonthend+$nunmonthstart) { 
61              //如果为显示的是今天则用红色背景显示 
62              if($iv==date("d") && date("n")==$pmonth && date("Y")==$pyear){ 
63                  print( "<td align=center bgcolor=ffaaaa><a href='#' target=_blank>".$iv."</a></td>" ); 
64              }else{ 
65                  print( "<td align=center><a href='#' target=_blank>".$iv."</a></td>" ); 
66              } 
67          }else{ 
68              print( "<td> </td>" ); 
69          } 
70  
71          //如果能被7整除(每行显示7个)则输出一个换行 
72          if ($i%7 ==0) { 
73              print( "</tr><tr align=center bgcolor=ffffff height=19>" ); 
74          } 
75      } 
76?> 
77</tr> 
78</table> 
79</body> 
80</html>

原文地址: http://ajax.cnrui.cn/article/2/1/2006/20061116834.shtml
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值