效果图
代码块
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script>
var weekday=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var monthdays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var mydate=new Date();
var myyear=mydate.getFullYear();
var mymouth=mydate.getMonth();
var myday=mydate.getDate();
var myweek=mydate.getDay();
if(myyear%4==0&&myyear%100==0||myyear%400==0){
mouthdays[1]=29;
}
mydate.setDate(1);
var m=mydate.getDay();
document.write(m);
document.write("<table width='400' border='1'>");
document.write("<tr align='center'><td colspan='7' >"+myyear+"年"+(++mymouth)+"月"+myday+"日"+" </td></tr>");
var n=1;
mymouth--;
document.write("<tr>");
for(var i=0;i<7;i++)
{
document.write("<td>");
document.write(weekday[i]);
document.write("</td>");
}
document.write("</tr>");
for(var i=0;i<5;i++){
if(m>0){
document.write("<tr>");
for(var j=0;j<m;j++){
document.write("<td>");
document.write(" ");
document.write("</td>");
}
for(var k=m;k<7;k++){
if(n==myday){
document.write("<td style='color:red'>");
document.write(n);
document.write("</td>");
}
else{
document.write("<td >");
document.write(n);
document.write("</td>");
}
n++
}
document.write("</tr>");
m=0;
}
if(m==0){
document.write("<tr>");
for(var k=0;k<7;k++){
if(n>monthdays[mymouth]){
document.write("<td>");
document.write(" ");
document.write("</td>");
}
else{
if(n==myday){
document.write("<td style='color:red'>");
document.write(n);
document.write("</td>");
}
else{
document.write("<td >");
document.write(n);
document.write("</td>");
}
n++;
}
}
document.write("</tr>");
}
}
document.write("</table>");
</script>
</body>
</html>