First look at the effect chart, the effect is relatively simple:
Specific code:
JavaScript code
Determine if the leap year function isleapyear (year) {if (year%400==0) | | (year%4==0 && year%100!=0))
{return true;
return false;
}//Calendar function Createcalendar (year,month,date) {var d=new date (); if (!year | | year<=0) {cur_year=d.getfullyear ();
Year}else{Cur_year=year; } if (!month | | month<=0) {cur_mon=d.getmonth ();
Date}else{cur_mon=month-1; } if (!date | | date<=0) {cur_date=d.getdate ();
Date}else{cur_date=date; } month_days=new Array (31,28+isleapyear (D.getfullyear ()), 31,30,31,30,31,31,30,31,30,31);
Days of the Month array month_firstday_date=new date (cur_year,cur_mon,1);
Monthdays=month_days[cur_mon]; Monthfirstday=month_firstday_date.getday (); The first day of the month is the Week Lines=math.ceil ((monthdays+monthfirstday)/7);
The number of rows required for the table var calendarbody= "";
for (Var i=0;i<lines;i++) {calendarbody+= "<tr class= ' line ' >"; for (Var j=0;j<7;j++) {idx=i*7+j;//cell Natural serial number if (i==0&& idx<monthfirstday) {calendarbody+= "<td class= ' empty ' ></td>";
}else if (idx<monthdays+monthfirstday) {var date=idx+1-monthfirstday; if (date==cur_date && cur_mon==d.getmonth () && cur_year==d.getfullyear ()) {calendarbody+= "<td
class= ' Today ' > ' +date+ "</td>";
}else{calendarbody+= "<td>" +date+ "</td>";
}}else{calendarbody+= "<td class= ' empty ' ></td>";
}} calendarbody+= "</tr>";
return calendarbody; }