Select remove() 方法

Select 對象參考手冊 Select 對象

定義和用法

remove() 方法用於從下拉列表刪除選項。

語法

selectObject.remove(index)

參數 描述
index 必需。規定要刪除的選項的索引號。


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 remove() 方法


實例

實例

下麵的例子可從列表中刪除被選的選項:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
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="移除選項">
</form>

</body>
</html>



實例

更多實例


Select 對象參考手冊 Select 對象