码迷,mamicode.com
首页 > 编程语言 > 详细

javascript万年历

时间:2015-05-28 18:27:08      阅读:163      评论:0      收藏:0      [点我收藏+]

标签: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>


javascript万年历

标签:javascript万年历

原文地址:http://9865481.blog.51cto.com/9855481/1655969

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!