日曆


<head>
<title>日曆</title>
</head>
<body>
   <div align="center">
<script type="text/javascript">
var m = new Date();
function Leap(k){
  if (k % 400 == 0 || (k % 4 == 0 && k % 100 != 0)) {   
            return true;   
        } else {   
            return false;   
        }   
}
     function showDate(year,month,day) {
      var i=1;
      var j1=1;
      var theday=1;
      var max;
      var tempday;
  
/*  var k=2012;
var j=8; */


var   s   =  ""+ year +"-" + month +"-"+1;   
var b = new Date(Date.parse(s.replace(/\-/g,"/")));  
/*alert(b.getDay());  
alert(s);*/

document.write("<input type='button' value='返回現在時間' οnclick='showCurrentDate();' >");
      document.write ("<b><h1  align='center'><font color='blue'>" + ( year ) + "年" + ( month ) +"月"+ "</font></h1></b>");
 document.write ("<hr>");
 document.write ("<hr>");
      document.write ("<table border='3' width='400' height='200' align='center'>");
      document.write ("<tr>");
      document.write ("<td height='30' width='50'><font color='red'>星期日</font></td>");
      document.write ("<td height='30' width='50'>星期一</td>");
      document.write ("<td height='30' width='50'>星期二</td>");
      document.write ("<td height='30' width='50'>星期三</td>");
      document.write ("<td height='30' width='50'>星期四</td>");
      document.write ("<td height='30' width='50'>星期五</td>");
      document.write ("<td height='30' width='50'><font color='red'>星期六</font></td>");
      document.write ("</tr>");
        
      tempday=b.getDay();      


 if(month ==1||month==3||month==5||month==7||month==8||month==10||month==12)   {
          max=31;   }
      if(month ==4||month==6||month==9||month==11){   
          max=30;   }
       if (month ==2)   {
           max=Leap(year)?28:29;}   
      for(i=0;i<6;i++) {
       document.write ("<tr>");
       for(j1=0;j1<=6;j1++) {
        document.write ("<td height='30' width='50'>");
         if(j1>=(tempday)) {
         tempday=0;
         if(theday<=max) {
          document.write ("<a title=" + year + "-" + month + "-" +theday+">");
           if(j1==0||j1==6)
           document.write ("<font color='red'>" + (theday==day?"[" + theday+"]":theday) + "</font></a>");
 
          else
           document.write ((theday==day?"[" + theday+"]":theday) + "</a>");
          theday++;
         }
        }
        document.write ("</td>");
       }
       document.write ("</tr>");
      }
      document.write ("</table>");
     }     
 
 
 
   function clicks(){
document.write("<form>");
document.write("<input type='text' name='setYear'>年");
document.write("<input type ='text' name='setMonth'>月");
    document.write("<input type='button' value='確定' target='_blank' οnclick='showDate(setYear.value,setMonth.value);' >");
document.write("</form>");}
</script>
    <script language="javascript">
    
     


     function showCurrentDate() {
var today = new Date();
//在日曆中顯示當前日期
  showDate(today.getFullYear(),today.getMonth()+1,today.getDate())
     }
clicks();
showCurrentDate();
    </script>
</div>
   </div>
<body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章