惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧!
//填充出生月数下拉列表 var months=new Array(new Option("12",12),new Option("11",11),new Option("10",10), new Option("9",9),new Option("8",8),new Option("7",7),new Option("6",6), new Option("5",5),new Option("4",4),new Option("3",3), new Option("2",2),new Option("1",1)); function loadMonths(){ for(var i=0;i<months.length;i++){ document.getElementById("month").appendChild(months[i]); } }
//填充出生日数下拉列表 var days=new Array(new Option("1",1),new Option("2",2),new Option("3",3), new Option("4",4),new Option("5",5),new Option("6",6),new Option("7",7), new Option("8",8),new Option("9",9),new Option("10",10), new Option("11",11),new Option("12",12),new Option("13",13), new Option("14",14),new Option("15",15),new Option("16",16),new Option("17",17), new Option("18",18),new Option("19",19),new Option("20",20), new Option("21",21),new Option("22",22),new Option("23",23),new Option("24",24), new Option("25",25),new Option("26",26),new Option("27",27),new Option("28",28), new Option("29",29),new Option("30",30),new Option("31",31)); function loadDays(){ var selectMonth=document.getElementById("month"); var index=selectMonth.selectedIndex; var value=parseInt(selectMonth.options[index].value); switch(value){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: for(var i=0;i<days.length;i++){ document.getElementById("day").appendChild(days[i]); };break; default:for(var i=0;i<days.length-1;i++){ document.getElementById("day").appendChild(days[i]); //document.getElementById("day").options.add(days[i]); 与上条语句作用相同 } } }