<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文件</title> </head> <script language="javascript" > function YearMonthDay(){ fo=document.form1; foday=fo.day; MonHead=[31,28,31,30,31,30,31,31,30,31,30,31]; //設定年 y=new Date().getFullYear(); start_y = y-90; //開始年份 end_y = y-10; //結束年份 for(i=start_y;i<=end_y;i++) fo.year.options.add(new Option(i,i)); fo.year.options.value=y;//current year //設定月 m=new Date().getMonth(); for(i=1;i<=12;i++) fo.month.options.add(new Option(i,i)); fo.month.options.value=m+1;//current month //設定日 d=new Date().getDay(); n=MonHead[m]; if(m==1&&IsRunYear(yearValue)) n++; day(n); fo.day.options.value=d+1;//curren day } //onchange of year function yy(str){ monthValue=fo.month.options[fo.month.selectedIndex].value; if(monthValue==""){ var foday=document.form1.day; optionClear(foday); return; } var n=MonHead[monthValue-1]; if(monthValue==2&&IsRunYear(str)) n++; day(n); } //onchange of month function mm(ab){ yearValue=fo.year.options[fo.year.selectedIndex].value; if(yearValue==""){ optionClear(foday); return; } var n=MonHead[ab-1]; if(ab==2&&IsRunYear(yearValue)) n++; day(n); } function day(ab){ optionClear(foday); for(var i=1;i<=ab;i++) foday.options.add(new Option(i,i)); } function optionClear(ab){ for(var i=ab.options.length;i>0;i--) ab.remove(i); } function IsRunYear(year){ return(0==year%4 && (year!=0 || year==0)); } </script> <body onload="YearMonthDay()"> 在body中輸入onload事件onload="YearMonthDay()" <form name="form1"> <select name="year" onchange="yy(this.value)"> <option value=""></option> </select>年 <select name="month" onchange="mm(this.value)"> <option value=""></option> </select>月 <select name="day"> <option value=""></option> </select>日 </form> </body> </html>