Select remove() 方法

定义和用法
remove() 方法用于从下拉列表删除选项。
语法
selectObject.remove(index)
参数 | 描述 |
---|---|
index | 必需。规定要删除的选项的索引号。 |
浏览器支持
所有主要浏览器都支持 remove() 方法
实例
实例
下面的例子可从列表中删除被选的选项:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>悠悠之家(uoften.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>
<html>
<head>
<meta charset="utf-8">
<title>悠悠之家(uoften.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>

更多实例
