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>

 

相关文章:

  • 2021-07-11
  • 2021-12-16
  • 2021-07-19
  • 2021-10-27
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2021-09-24
  • 2022-01-12
  • 2021-06-07
  • 2022-02-03
  • 2021-11-03
相关资源
相似解决方案