打印本文 打印本文 关闭窗口 关闭窗口
多种Web脚本语言下的日历实现
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4191  更新时间:2009/4/23 10:33:30  文章录入:mintao  责任编辑:mintao
bsp;      if i>nunmonthstart and i<=nunmonthend+nunmonthstart then
60            '如果为显示的是今天则用红色背景显示
61            if iv=Day(now) and month(now)=pmonth and year(now)=pyear then
62                response.write( "<td align=center bgcolor=ffaaaa><a href='#' target=_blank>" & iv & "</a></td>")
63            else
64                response.write( "<td align=center><a href='#' target=_blank>" & iv & "</a></td>")
65            end if
66        else
67            response.write( "<td> </td>")
68        end if
69
70        '如果能被7整除(每行显示7个)则输出一个换行
71        if i mod 7=0 then
72            response.write( "</tr><tr align=center bgcolor=ffffff height=19>")
73        end if
74        i=i+1
75    loop
76%>
77</table>
78</body>

具体实现效果如下:

 

 

下面是根据上述算法和逻辑在PHP中的具体实现代码:

 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中通过该日历算法实现的具体代码
 8
 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="<<" onclick="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=">>" onclick="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

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口