HTML-DOM - Optionsobjekt
Optionsobjekt
Das Option-Objekt repräsentiert ein HTML-<option>-Element.
Greifen Sie auf ein Optionsobjekt zu
Sie können auf ein <option>-Element zugreifen, indem Sie getElementById() verwenden:
Beispiel
var x = document.getElementById("myOption");
Tipp: Sie können auch auf ein Option-Objekt zugreifen, indem Sie die Elementsammlung eines Formulars oder die Optionssammlung einer Dropdown-Liste durchsuchen .
Erstellen Sie ein Optionsobjekt
Sie können ein <option>-Element erstellen, indem Sie die Methode document.createElement() verwenden:
Beispiel
var x = document.createElement("OPTION");
Eigenschaften des Optionsobjekts
Property | Description |
---|---|
defaultSelected | Returns the default value of the selected attribute |
disabled | Sets or returns whether an option is disabled, or not |
form | Returns a reference to the form that contains the option |
index | Sets or returns the index position of an option in a drop-down list |
label | Sets or returns the value of the label attribute of an option in a drop-down list |
selected | Sets or returns the selected state of an option |
text | Sets or returns the text of an option |
value | Sets or returns the value of an option to be sent to the server |
Standardeigenschaften und -ereignisse
Das Option-Objekt unterstützt auch die Standardeigenschaften und -ereignisse .
Verwandte Seiten
HTML-Referenz: HTML <option>-Tag