javascript万年历
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<style type="text/css">
div{
position: absolute;
top: 0;
left: 600px;
}
h5{
margin-left: 88px;
}
table{
text-align: center;
border: 1px solid #aaa;
width: 273px;
height: 158px;
}
table td{
width: 39px;
height: 23px;
border: 1px solid #aaa;
}
</style>
</head>
<body>
<div>
<script type="text/javascript">
var today = new Date();
var date = today.getDate();
var theday = 1;
document.write("<h5>"+today.getFullYear()+"年"+(today.getMonth()+1)+"月"+"</h5>");
document.write("<table><tr>");
document.write("<td><font color=‘red‘>Sun</font></td>");
document.write("<td>Mon</td>");
document.write("<td>Tue</td>");
document.write("<td>Wed</td>");
document.write("<td>Thu</td>");
document.write("<td>Fir</td>");
document.write("<td><font color=‘red‘>Sat</font></td></tr>");
var month = today.getMonth()+1;
var max;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
max = 31;
break;
case 4:
case 6:
case 9:
case 11:
max = 30;
default:
max = 28;
}
today.setDate(1);
var temp = today.getDay();
for ( var i = 0; i < 6;i++) {
document.write("<tr>");
for ( var j = 0; j < 7; j++) {
document.write("<td>");
if( (j+1) > temp ) { //当天j+1小于temp时不执行代码
temp = 0; //temp赋值为0后下一个j可以从0开始执行代码
if( theday <= max){
if(theday == date) {
document.write("<font color=‘green‘>["+theday+"]</font>");
}
else if( j== 0 || j==6 ) {
document.write("<font color=‘red‘>"+theday+"</font>");
}
else{
document.write("<font color=‘blue‘>"+theday+"</font>")
}
}
theday++;
}
document.write("</td>");
}
document.write("</tr>");
}
document.write("</table>");
</script>
</body>
</html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。