Select、Option

2016 단어 select
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>


좋은 웹페이지 즐겨찾기