JavaScript日历

类别:网站制作 点击:0 评论:0 推荐:
想在Blog上加一个日历,找了半天都不满意,自己写了一个玩玩,运行效果就看左边的日历好了
 <style type="text/css"> .tdclass {font-size: 9pt; padding: 4px} </style> <table cellspacing="0" cellpadding="0" border="0" align="center" bordercolor="white"> <tr align="center" bgcolor="#7BA5CE"> <td class="tdclass"><font color="white">公元 <span id="layerYear"></span>年<span id="layerMonth"></span>月<span id="layerDay"></span>日 星期<span id="layerWeek"></span></font></td> </tr> <tr align="center"> <td> <span id="layerCalendar"></span> </td> </tr> <tr align="center"> <td class="tdclass" bgcolor="#7BA5CE"><font color="white">现在时间:<span id="layerNow"></span></font></td> </tr> </table> <script language="JavaScript" type="text/javascript"> <!-- // Written by caocao // [email protected] // http://nethermit.yeah.net var dayArray=new Array("日","一","二","三","四","五","六"); var monthArray=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var stringTable="<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" align=\"center\" bordercolor=\"#8F8FAF\"><tr bgcolor=\"#53A9FF\" align=\"center\">"; for (var i=0; i<dayArray.length; ++i) { stringTable+="<td class=\"tdclass\"><font color=\"white\"><b>"+dayArray[i]+"</b></font></td>"; } stringTable+="</tr>"; function setValue(tag, str) { document.getElementById(tag).innerHTML=str; } function showTime() { var today=new Date(); var currentYear=today.getFullYear() if (((currentYear%4==0)&&(currentYear%100!=0))||(currentYear%400==0)) monthArray[1]=29; var allDays=monthArray[today.getMonth()]; var currentWeek=today.getDay(); var currentDay=today.getDate(); var i=currentDay%7-currentWeek; var threshold=(7+i)%7; var isEnd=false; var stringAll=stringTable; while (true) { if (isEnd) { stringAll+="<td class=\"tdclass\" bgcolor=\"#EEEEEE\"> </td>"; if (i % 7==(threshold+6)%7) { stringAll+="</tr>"; break; } } else { if (i % 7==threshold) stringAll+="<tr align=\"center\">"; stringAll+=i>0?"<td class=\"tdclass\""+(i==currentDay?" bgcolor=\"#FEA477\" style=\"color: #FFFFFF\"":"")+"><b>"+i+"</b></td>":"<td class=\"tdclass\" bgcolor=\"#EEEEEE\"> </td>"; if (i % 7==(threshold+6)%7) { stringAll+="</tr>"; if (i==allDays) break; } if (i==allDays) isEnd=true; } ++i; } stringAll+="</table>"; setValue("layerYear", currentYear); setValue("layerMonth", today.getMonth()+1); setValue("layerDay", currentDay); setValue("layerWeek", dayArray[currentWeek]); setValue("layerCalendar", stringAll); setValue("layerNow", today.getHours()+":"+today.getMinutes()+":"+today.getSeconds()); setTimeout("showTime()",1000); } showTime() // --> </script>

本文地址:http://com.8s8s.com/it/it31234.htm