首页
微信
安卓
接口
移动
前端
专题
文档库
工具
网址
§
ITPOW
>>
文档
>>
JavaScript
>>
时间日期
月历
作者:chilleen 来源:
ITPOW
日期:2004-10-8
<script type="text/javascript"> <!-- today=new Date(); year=today.getFullYear(); month=today.getMonth(); date=today.getDate(); day=today.getDay(); month++; document.write("<table border='1' style='font-size:12px'>"); document.write("<tr><td colspan='7' align='center'>"+year+"年"+month+"月"+"</td></tr>"); document.write("<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td></td><td>六</td></tr>"); //计算这个月有多少天 var days; if(month!=2) { if(month<=7) { days=((month%2)==0)?30:31; } else { days=((month%2)==0)?31:30; } } else { if(((year%4==0)&&(year%100!=0))||(year%400==0)) { //闰年 days=29; } else { days=28; } } //计算这个月的第一天是星期几 firstdate_day=day-(date%7-1); //计算需要几行 var rows=4; if(((days+firstdate_day)/7)>5) { rows=6; } else if(((days+firstdate_day)/7)>4) { rows=5; } //开始显示日期 var datepos=1; for(i=0;i<rows;i++) { document.write("<tr>"); for(j=0;j<7;j++) { document.write("<td>") if(((i==0)&&(j<firstdate_day))||(datepos>days)) document.write(" "); else { if(date==datepos) { document.write("<font color='#FF0000'>"); document.write(datepos); document.write("</font>"); } else document.write(datepos); ++datepos; } document.write("</td>"); } document.write("</tr>"); } document.write("</table>"); --> </script>
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
相关文章
创建于2005年
渝ICP备05010272号-1
电邮:
cftea@126.com
即将跳转...