我想隐藏select里面索引为1的选项,然后我另外点个按钮,在把这个隐藏的选项恢复,这个怎么做呢?

解决方案 »

  1.   

    隐藏select中的option
      

  2.   

    还真不知道 IE 和 FF option事件也这么多不一样
    <select id="osel">
    <option value="1">1</option>
    <option value="3s">2</option>
    </select>
    <input type="button" value="Hide" onclick="Hide()">
    <input type="button" value="Show" onclick="Show()">
    <script type="text/javascript">
    <!--
    var osel = document.getElementById('osel'), arr = [];
    function Hide(){
     if(/*@cc_on!@*/0){
    arr.push(osel.options[1].text,osel.options[1].value);
    osel.options.removeChild(osel.options[1]);
     }else{
    osel.options[1].style.display = "none";
     }
    }function Show(){
     if(/*@cc_on!@*/0){
    osel.options[1] = new Option(arr[0],arr[1]);
     }else{
    osel.options[1].style.display = "block";
     }
    }//-->
    </script>
      

  3.   

    <html><head><title></title>
    <script type="text/javascript">
    var saveValue=[];
    function getValue()
    {
        var sel=document.getElementById("sel");
        for(var i=0;i<sel.options.length;i++)
        {
            saveValue[i]=sel.options[i].value;
        }
        
    }
    function removeFirstValue()
    {   
        getValue();
        var sel=document.getElementById("sel");
        sel.remove(1);
    }
    function show()
    {
        var sel=document.getElementById("sel");
        for(var i=0;i<saveValue.length;i++)
        {
            
            sel.options[i]=new Option(i,saveValue[i]);
        }
    }
    window.onload=removeFirstValue;
    </script>
    </head><body>
    <select id="sel">
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option></select>
    <input  type="button" onclick="show();" value="show">
    </body></html>