HTML-DOM Select Methode remove ()
Definition und Verwendung
remove () Methode wird verwendet, um die Option aus der Dropdown-Liste zu entfernen.
Grammatik
selectObject.remove(index)
参数 | 描述 |
---|---|
index | 必需。规定要删除的选项的索引号。 |
Browser-Unterstützung
Alle gängigen Browser unterstützen () -Methode entfernen
Beispiele
Beispiele
Die folgenden Beispiele können Option löschen wird aus der Liste ausgewählt:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Titel> Dieses Tutorial (w3big.com) </ title>
<Script>
Funktion removeOption () {
var x = document.getElementById ( "MYSELECT");
x.remove (x.selectedIndex);
}
</ Script>
</ Head>
<Body>
<Form>
<Wählen Sie id = "MYSELECT">
<Option> Apple-</ option>
<Option> Birne </ option>
<Option> Banana </ option>
<Option> Orange </ option>
</ Select>
<Input type = "button" Onclick = "removeOption ()" value = "entfernen Optionen">
</ Form>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Titel> Dieses Tutorial (w3big.com) </ title>
<Script>
Funktion removeOption () {
var x = document.getElementById ( "MYSELECT");
x.remove (x.selectedIndex);
}
</ Script>
</ Head>
<Body>
<Form>
<Wählen Sie id = "MYSELECT">
<Option> Apple-</ option>
<Option> Birne </ option>
<Option> Banana </ option>
<Option> Orange </ option>
</ Select>
<Input type = "button" Onclick = "removeOption ()" value = "entfernen Optionen">
</ Form>
</ Body>
</ Html>
Versuchen »
Weitere Beispiele
Löschen Sie die letzte Option aus der Dropdown-Liste
Objekte auswählen