语法:向一个下拉框添加属性
document.getElementById("ddlControl").options.add(new?Option(text,value));
<script language="javascript" type="text/javascript"> //添加下拉框选项 function addOption() { var obj=document.getElementById('year'); for(var i=1961;i<=2061;i++) obj.options.add(new Option(i+"年",i)); } //下拉框选项默认为当前系统年 function setYear() { var obj=document.getElementById('year'); var data=new Date(); var year=data.getFullYear(); for(var i=0;i<=100;i++) { if(obj.options[i].value == year) { obj.options[i].selected=true; return; } } } </script> <body> //先有下拉框 <select name="year" id="year"> </select> <script language="javascript" type="text/javascript"> addOption(); setYear(); </script> </body>
?
<!--EndFragment-->