js移除option值的方法

来源:互联网 发布:淘宝 大类目小类目 编辑:程序博客网 时间:2024/04/30 16:46

   在HTML中的select下拉列表中,我们有时想删除一些option的值,用了display=“none”,不起作用。那么用什么方法可以解决呢。

  经过反复的探索及研究,如下是我实现的功能。删除其中的一些数据

    <html>

<body>

<select  id="selectId"  name="selectId">

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

<option value="6">6</option>

<option value="7">7</option>

</select>

<script language="javacript">

var indexcode="hahahha"

 var j=document.getElementById("selectId").options.length;

for(var i=0;i<j;i++){

var obj=document.getElementById("selectId").options(i);

var str=obj.value;

var newStr=new Array();

new Str=str.substr(str.indexOf(",")+1);

var code=new array();

code=newStr.indexOf(indexcode);

if(code!=0){

document.getElementById("selectId").remove(i);

i--;

j--;

}

}

</script>

</body>

 

</html>

原创粉丝点击