javascript 动态创建 Option选项 时间:2020-05-12 人气:0 <html> <head> <title>javascripttest</title> <script type="text/javascript"> function setDay() { var themonth=document.getElementById("month"); var themaxmonthday=31; if(themonth.value=="2") { themaxmonthday=28; } var theday=document.getElementById("day"); var tempdaylength=theday.options.length; for(var j=tempdaylength;j>0;j--) { theday.options.remove(j); } for(var i=1;i<=themaxmonthday;i++) { var theOption=document.createElement("option"); theOption.innerHTML=i+"日"; theOption.value=i; theday.appendChild(theOption); } } </script> </head> <body> <select id="month" onchange="setDay()"> <option value="1">1月</option> <option value="2">2月</option> <option value="3">3月</option> <option value="4">4月</option> <option value="5">5月</option> <option value="6">6月</option> <option value="12">12月</option> </select> <select id="day"> </select> </body> </html> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容