<title> Day three Drop-down frame linkage </title> <meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' > <meta name= ' author ' content= ' Oiea ' > <script language= "JavaScript" > <!-- function Initdate (year,month,day) { The initial number of days per month Mondays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; The current year var y = new Date (). getFullYear (); The current month var m = new Date (). getmonth () +1; JavaScript Month is 0-11 But before the day var d = new Date (). GetDate ();
This year, 2 years back, fill year dropdown box for (var i = y; I < (y+2); i++) { Year.options.add (New Option (i,i)); } Select this year Year.value=y; Fill Month Drop-down Box for (var i = 1; I <= i++) { Month.options.add (New Option (i,i)); } Select Month Month.value = m;
Get initialization days for the month var n = mondays[m-1]; If February, the number of days plus 1 if (m = = 2 && isleapyear (Year.options[year.selectedindex].value)) n++; Fill Date drop down box Createday (N,day); Selected day Day.value = new Date (). GetDate (); } function Change (year,month,day)//month changes, change day { &nbs p; var y = year.options[year.selectedindex].value; var m = month.options[month.selectedindex].value; //if (m = = "") { clearoptions (day); return;} var n = mondays[m-1]; if (M ==2 && isleapyear (y)) &NBSP;&NB sp; { n++; } createday (n,day) & nbsp } function Createday (n,day)//Fill Date dropdown box { Clear the dropdown box Clearoptions (day); A few days, just write a few for (var i=1; i<=n; i++) { Day.options.add (New Option (i,i)); } } function Clearoptions (CTL)//Delete all options in the Drop-down box { for (var i=ctl.options.length-1; i>=0; i--) { Ctl.remove (i); } }
function Isleapyear (year)//judge whether leap year { Return (Year%4==0 | | (year%100 ==0 && year%400 = 0)); } --> </script> <body onload= "Initdate (document.form1.select_year,document.form1.select_month,document.form1.select_day)" > <form name= "Form1" > <select name= "Select_year" onchange= "Change (this, Document.form1.select_month, Document.form1.select_day)" > </select>year <select name= "Select_month" onchange= "Change (document.form1.select_year, This,document.form1.select_day)" > </select>month <select name= "Select_day" ></select>day </form> </body> |