<select id=select1>
<option>123</option>
</select>
<button onclick=get1()>Add</button>
<script>
function get1(){
var strName = 'aa';
var objOption = new Option(strName,strName,true,true);
document.all.select1.options.add(objOption);
}
</script>

解决方案 »

  1.   

    我是一个循环,添加N个值
    我发觉这样好像那个selected的值没有显示,而显示的是最后一个值
    还有,在下拉框里多了一行空行
      

  2.   

    我刚才看错了,好像没有起到作用,selected的值是我预先设置的那个
      

  3.   

    那你就添加完毕再设置selected属性,如果在new Option()里面设置参数,总是最后一个被选择空行现象没发现
      

  4.   

    你调试我的代码,按Add按钮后,选择的是aa选项,而不是123了
      

  5.   

    空行已解决,是我在添加前加了form1.select1.options.length=1;
    但我不知到如何在添加完后,在设置selected属性,还望指教,谢谢!
      

  6.   

    form1.select1.options[i].selected = true;其中i是变量,表示所有选项集合的下标,下标从0开始,例如第一个选项是options[0]