日历

<script>
 function getTime() {
     // initialize time-related variables with current time settings 
     var now = new Date();
     var hour = now.getHours();
     var minute = now.getMinutes();
     now = null;
     var ampm = "";
     // validate hour values and set value of ampm 
     if (hour>= 12) {
         hour -= 12;
		 ampm = "PM";
     } else {
         ampm = "AM";
     }
     hour = (hour == 0) ? 12 : hour;
     // add zero digit to a one digit minute 
     if (minute <10) minute = "0" + minute;
     // do not parse this number! 
     // return time string 
     return hour + ": " + minute + "" + ampm;
 }

 function leapYear(year) {
     if (year % 4 == 0)
     // basic rule 
     return true;
     // is leap year 
     return false;
     // is not leap year 
 }

 function getDays(month, year) {
     // create array to hold number of days in each month
     var ar = new Array(12);
     ar[0] = 31;
     // January 
     ar[1] = (leapYear(year)) ? 29 : 28;
     // February 
     ar[2] = 31;
     // March 
     ar[3] = 30;
     // April 
     ar[4] = 31;
     // May 
     ar[5] = 30;
     // June 
     ar[6] = 31;
     // July 
     ar[7] = 31;
     // August 
     ar[8] = 30;
     // September 
     ar[9] = 31;
     // October 
     ar[10] = 30;
     // November 
     ar[11] = 31;
     // December 
     // return number of days in the specified month (parameter) 
     return ar[month];
 }

 function getMonthName(month) {
     // create array to hold name of each month 
     var ar = new Array(12);
     ar[0] = "01";
     ar[1] = "02";
     ar[2] = "03";
     ar[3] = "04";
     ar[4] = "05";
     ar[5] = "06";
     ar[6] = "07";
     ar[7] = "08";
     ar[8] = "09";
     ar[9] = "10";
     ar[10] = "11";
     ar[11] = "12";
     // return name of specified month (parameter) 
     return ar[month];
 }

 function setCal() {
     // standard time attributes 
     var now = new Date();
     var year = now.getYear();
     var month = now.getMonth();
     var monthName = getMonthName(month);
     var date = now.getDate();
     now = null;
     // create instance of first day of month, and extract the day on which it occurs 
     var firstDayInstance = new Date(year, month, 1);
     var firstDay = firstDayInstance.getDay();
     firstDayInstance = null;
     // number of days in current month 
     var days = getDays(month, year);
     // call function to draw calendar 
     drawCal(firstDay + 1, days, date, monthName, year);
 }

 function drawCal(firstDay, lastDate, date, monthName, year) {
     var tableScript = "";
     tableScript += "<table border='0' cellpadding='2' cellspacing='0' width=100% bordercolordark='#ffffff'>"
     tableScript += " <tr>"
     tableScript += " <td align='center'></td>"
     tableScript += " </tr>"
     tableScript += " <tr>"
     tableScript += " <td>"
     tableScript += " <table width='100%' align=center border='0' cellspacing='2' cellpadding='0'>"
     tableScript += " <tr>"
     tableScript += " <td>日</td>"
     tableScript += " <td>一</td>"
     tableScript += " <td>二</td>"
     tableScript += " <td>三</td>"
     tableScript += " <td>四</td>"
     tableScript += " <td>五</td>"
     tableScript += " <td>六</td>"
     tableScript += " </tr>"
     var digit = 1;
     var curCell = 1;
     var day = "";
     for (var row = 1; row <= Math.ceil((lastDate + firstDay-1) / 7); ++row) {
         tableScript += "<tr align = 'right'valign = 'top'> "
         for (var col = 1; col <= 7; ++col) {
             if (digit> lastDate) break;
             if (curCell <firstDay) {
                 tableScript += " <td> </td>";
                 curCell++;
             } else {
                 if (digit <10) day = year + '-' + monthName + '-0' + digit;
                 else day = year + '-' + monthName + '-' + digit;
                 if (digit == date) {
                     // current cell represent today's date 
                     tableScript += " <td align = center> ";
                     tableScript += " <a HREF = 'showproduct.asp ? day = " + day + "'> " + " <font color = 'red'> <b> " + digit + " </b></font> </a>";
                     tableScript += "</td> ";
                 } else tableScript += " <td align = center> <a HREF = 'showproduct.asp ? day = " + day + "'> " + digit + " </a></td>";
                 digit++;
             }
         }
         tableScript += " </tr>"
     };
     tableScript += " ";
     tableScript += " </table> ";
     tableScript += " </td>";
     tableScript += " </tr> ";
     tableScript += " </table>";
     document.write(tableScript);
 }
 setCal();
</script>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部