HTML DOM remove() 方法

HTML DOM remove() 方法

 

remove() 方法用于从下拉列表删除选项。

语法

selectObject.remove(index)

index参数为规定要删除选项的索引号。 用在selectObject对象上

该方法从选项数组的指定位置移除 <option> 元素。如果指定的下标比 0 小,或者大于或等于选项的数目,remove() 方法会忽略它并什么也不做。

实例

下面的例子可从列表中删除被选的选项:

<html>
<head>
<script type="text/javascript">
function removeOption()
  {
  var x=document.getElementById("mySelect")
  x.remove(x.selectedIndex)
  }
</script>
</head>
<body>

<form>
<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
<input type="button" onclick="removeOption()"
value="Remove option">
</form>

</body>
</html>

 

posted @ 2016-09-03 10:51  nostic  阅读(1360)  评论(0编辑  收藏  举报