HTML DOM Select remove () method
Definition and Usage
remove () method is used to remove the option from the drop-down list.
grammar
selectObject.remove(index)
参数 | 描述 |
---|---|
index | 必需。规定要删除的选项的索引号。 |
Browser Support
All major browsers support remove () method
Examples
Examples
The following examples may delete option is selected from the list:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.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 = "remove options">
</ Form>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.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 = "remove options">
</ Form>
</ Body>
</ Html>
try it"
More examples
Delete the last option from the drop-down list
Select Objects