怎样删除select中指定的option?谢谢!

解决方案 »

  1.   


    selectObj.options.length=1;//删到只剩第一个
    selectObj.options.length=0;//删光
      

  2.   

    <select id="dr">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    </select><input onclick="remove()" type="button" value="删除选中" />
    <script>
    function remove(){
        var dr=document.getElementById("dr");
        dr.options.remove(dr.selectedIndex);
    }
    </script>
      

  3.   

    <!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>默认标题 by songpeng</title>
    <script language="JavaScript" type="text/javascript">
    function btnClick()
    {
    var objS = document.getElementById("s");
    for(var i=0;i<objS.options.length;i++)
    {
    if(objS.options[i].text == "百度")
    {
    objS.options.remove(i);
    return ;
    }
    }
    }
    </script>
    </head><body>
    <form>
    <select id="s">
    <option>谷歌</option>
    <option>百度</option>
    <option>搜狗</option>
    <option>中搜</option>
    </select>
    <input type = "button" onclick = "javascript:btnClick();" value = "删除“百度”" />
    </form>
    </body>
    </html>