假如select控件的ID为selIdvar selObj = document.getElementById("selId");
//添加选项
selObj.options.add(new Option('text','value'));//删除选项,i为选项的索引
selObj.options.remove(i);

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function addchooseval(strInput){
        var choosevallength=document.getElementById("chooseval").options.length; 
    document.getElementById("chooseval").options[choosevallength]=new Option(strInput.value,strInput.name);
    }
    </script>
    </head><body>
    <input type="text" id="newval" name="newval" onblur="addchooseval(this);" />
    <select name="chooseval" id="chooseval" size="1">
    <option value="java">java</option>
    <option value="javascript">javascript</option>
    </select>
    </body>
    </html>
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    var i=0;
    function test(){
    var obj = document.getElementById("sel");
    obj.options.add(new Option("我是新的"+i,i))
    obj.options[i].selected = true;
    i++;
    }function opclear(){
    var obj = document.getElementById("sel");
    for( var j=obj.options.length-1;j>=0;j-- )
    obj.options.remove(j); i = 0;
    }
    </script>
    </head><body>
    <select id="sel">
    </select>
    <input type="button" value="添加" id="button1" onclick="test();">
    <input type="button" value="清空" id="button2" onclick="opclear();">
    </body>
    </html>