<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<SELECT ID="oSelect">
  <OPTION VALUE="1">One</OPTION>
</SELECT><SCRIPT>
var oOption = document.createElement("OPTION");
document.form1.oSelect.options.add(oOption);
oOption.innerText = "Two";
oOption.value = "2";
</SCRIPT>
</form>
</body>
</html>

解决方案 »

  1.   

    document.all.oSelect.options.add(oOption);
      

  2.   

    谢谢两位!象document.form1、document.all什么时候必须要,什么时候可以不要?
      

  3.   

    我想把两个option项用remove方法清除,代码如下<html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF" text="#000000">
    <form name="form1" method="post" action="">
    <SELECT ID="oSelect">
      <OPTION VALUE="1">One</OPTION>
    </SELECT><SCRIPT>
    var oOption = document.createElement("OPTION");
    form1.oSelect.options.add(oOption);
    oOption.innerText = "Two";
    oOption.value = "2";
    oSelect.options.remove(0);
    oSelect.options.remove(1);//oSelect.options.remove(0);
    </SCRIPT>
    </form>
    </body>
    </html>不行,第二项并没有被清除,改成这样两句就可以了:
    oSelect.options.remove(0);
    oSelect.options.remove(0);为什么?
      

  4.   

    要删除的话,从后边往前删除就可以了。
    oSelect.options.remove(1);
    oSelect.options.remove(0);
      

  5.   

    谢谢sun1979song(十步杀一人),为什么从前往后删除不行?
      

  6.   

    oSelect.options.remove(0);
    oSelect.options.remove(1);//oSelect.options.remove(0);删除了一个,下面的一个就自动上移了啊~~~一般都需要指出引用的对象的全名:)
      

  7.   

    所以实际上
    oSelect.options.remove(0);
    oSelect.options.remove(0);
    有错误,应该是:
    document.form1.oSelect.options.remove(0);
    document.form1.oSelect.options.remove(0);