Select、Option

1.删除Select控件的某个Option,没有提供隐藏的方法。

function RemoveMe(){

    document.getElementById("test").options[1].parentNode.removeChild(document.getElementById("test").options[2]);

}

2.动态生成Option。

<HTML>

 <HEAD>

  <TITLE> Test </TITLE>

  <META NAME="Generator" CONTENT="EditPlus">

  <META NAME="Author" CONTENT="">

  <META NAME="Keywords" CONTENT="">

  <META NAME="Description" CONTENT="">

  <script language="javascript">

    //下拉框的内容

    function initcolorArray(){    

        var colorArray=new Array();

        colorArray[0]="红色";

        colorArray[1]="白色";

        colorArray[2]="蓝色";

        colorArray[3]="黑色";

        colorArray[4]="橙色";

        colorArray[5]="绿色";

        colorArray[6]="灰色";

        colorArray[7]="紫色";

        colorArray[8]="墨绿色";

        colorArray[9]="暗红色";

        return colorArray;

    }

    //点击选择框动态生成下拉框中内容

    function showcolor(obj){

        var colorSel= document.getElementById("example");

        var array = initcolorArray();

        for(i=0;i<array.length;i++){

            colorSel.options[i]=new Option(array[i],i);

        }

        colorSel.options[9].selected=true;

        obj.onclick="";

    }

    //初始化选择框

    function init(){

        var colorSel= document.getElementById("example");

        colorSel.options[0]=new Option("暗红色",0);

    }    

    window.onload=initcolorArray;

</script>

 </HEAD>

 <BODY>

    颜色:<select style="width:120px" onMouseOver="showcolor(this);this.onmouseover=null;alert('here');" onclick="showcolor(this)" id="example"></select>

 </BODY>

 <script language="javascript">

    init();

 </script>

</HTML>

 

你可能感兴趣的:(select)