以下是代码:
<HTML>
<HEAD>
<TITLE>日历</TITLE>
</HEAD>
<BODY οnlοad="load()">
<SCRIPT LANGUAGE="JavaScript">
function TGetDaysInMonth(iMonth, iYear) {
var dPrevDate = new Date(iYear, iMonth, 0);
return dPrevDate.getDate();
}
function TUpdateCal(iYear, iMonth) {
var dDate=new Date();
daysInMonth = TGetDaysInMonth(iMonth, iYear);
while(document.all.tbSelDay.childNodes.length>0)
{
document.all.tbSelDay.removeChild(document.all.tbSelDay.childNodes[0]);
}
for (d = 1; d <= parseInt(daysInMonth); d++) {
option=document.createElement("option");
option.value=d;
option.appendChild(document.createTextNode(d));
document.all.tbSelDay.appendChild(option);
if(d==dDate.getDate())
{
option.selected=true;
}
}
}
function load()
{
<!--出始化年-->
var dDate = new Date();
var dCurYear = dDate.getFullYear();
for(var i=dCurYear-10;i<dCurYear+5;i++)
{
option=document.createElement("option");
option.value=i;
option.appendChild(document.createTextNode(i));
document.all.tbSelYear.appendChild(option);
if(i==dCurYear)
{
option.selected=true;
}
}
<!--出始化月-->
for(var i=1;i<=12;i++)
{
option=document.createElement("option");
option.value=i;
option.appendChild(document.createTextNode(i));
document.all.tbSelMonth.appendChild(option);
if(i==(dDate.getMonth()+1))
{
option.selected=true;
}
}
}
</script>
<form name="frmCalendarSample" method="post" action="">
年:
<select name="tbSelYear" οnchange='TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>
</select>
月:
<select name="tbSelMonth" style="width: 50px" οnchange='TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>
</select>
日:
<select name="tbSelDay"></select>
<script language="JavaScript">
TUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value);
</script>
</form>
</BODY>
</HTML>
你也可以直接下载:
http://cn.ziddu.com/download/264275/date.txt.html