JavaScript实现的万年历 |
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE> <META content="text/html; charset=gb2312" http-equiv=Content-Type> <SCRIPT language=JavaScript> function monthday(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11) { this[0] = d0; this[1] = d1; this[2] = d2; this[3] = d3; this[4] = d4; this[5] = d5; this[6] = d6; this[7] = d7; this[8] = d8; this[9] = d9; this[10] = d10; this[11] = d11; }; function showcalendar(mode) { var thisDay; var month; var year; var monthDays = new monthday(31,28,31,30,31,30,31,31,30,31,30,31); var today; year=document.forms[1].elements[0].value; month=document.forms[1].elements[1].value; if (mode==0) today=new Date(year,month,1); if (mode==1) <!-- year -1 --> { document.forms[1].elements[0].value=year -1; today=new Date(year -1,month,1); } if (mode==2) <!-- year +1 --> { ++year; document.forms[1].elements[0].value=year; today=new Date(year,month,1); } if (mode==3) <!-- mont -1 --> { document.forms[1].elements[1].value=month -1; today=new Date(year,month-1,1); } if (mode==4) <!-- year -1 --> { ++month; document.forms[1].elements[1].value=month; today=new Date(year,month,1); } year = today.getYear(); if (year<2000) year=year+1900; thisDay = today.getDate(); if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29; nDays = monthDays[today.getMonth()]; firstDay = today; firstDay.setDate(1); testMe = firstDay.getDate(); if (testMe == 2) firstDay.setDate(0); startDay = firstDay.getDay(); document.forms[0].elements[0].value=" "+year+ '年'+(today.getMonth()+1)+'月 '; for (i=1; i<=startDay;i++) { document.forms[0].elements[i].value=" "; } for (i=1; i<=nDays; i++) { if (i>=10) document.forms[0].elements[i+startDay].value=" "+i; else document.forms[0].elements[i+startDay].value=" "+i; } for (i=nDays+startDay+1;i<=42;i++) { document.forms[0].elements[i].value=" "; } } </SCRIPT> <META content="MSHTML 5.00.2919.6307" name=GENERATOR></HEAD> <BODY> <FORM> <TABLE align=center background="" bgColor=#7d9ec0 border=1 borderColor=#00008b borderColorDark=#00005e borderColorLight=#afeeee cellPadding=1 cellSpacing=1> <TBODY> <TR> <TH colSpan=7><FONT size=2><INPUT type=button value=" 表头 "></FONT> <TR> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周日</FONT> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周一</FONT> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周二</FONT> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周三</FONT> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周四</FONT> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周五</FONT> <TH style="BORDER-BOTTOM: #ffffe0 2px outset; BORDER-LEFT: #ffffe0 2px outset; BORDER-RIGHT: #ffffe0 2px outset; BORDER-TOP: #ffffe0 2px outset"><FONT size=2>周六 </FONT> <TR> <SCRIPT language=JavaScript> var column=0; for (i=0; i<=41; i++) { document.write("<TD align='center'><input value=' ' type='button' name='d"+i+"'></td>"); column++; if (column==7) { document.write("<tr>"); column=0; } } </SCRIPT> </TR></TBODY></TABLE></FORM> <FORM> <INPUT name=year type=hidden value=" "> <INPUT name=month type=hidden value=" "> <INPUT name=y_add1 onclick="showcalendar(1)" type=button value=year-> <INPUT name=y_dec1 onclick="showcalendar(2)" type=button value=year+> <INPUT name=m_add1 onclick="showcalendar(3)" type=button value=month-> <INPUT name=m_dec1 onclick="showcalendar(4)" type=button value=month+> </FORM> <SCRIPT language=JavaScript> var thisdate=new Date(); document.forms[1].elements[0].value=thisdate.getYear(); document.forms[1].elements[1].value=thisdate.getMonth(); <!--var today = new Date(99,7,13);--> showcalendar(0); </script> </FORM></BODY></HTML> |