Obiekt opcji HTML DOM
Obiekt opcji
Obiekt Option reprezentuje element HTML <option>.
Uzyskaj dostęp do obiektu opcji
Możesz uzyskać dostęp do elementu <option> za pomocą getElementById():
Przykład
var x = document.getElementById("myOption");
Porada: Możesz również uzyskać dostęp do obiektu Option, przeszukując kolekcję elementów formularza lub kolekcję opcji listy rozwijanej.
Utwórz obiekt opcji
Możesz utworzyć element <option> za pomocą metody document.createElement():
Przykład
var x = document.createElement("OPTION");
Opcja Właściwości obiektu
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 |
Standardowe właściwości i zdarzenia
Obiekt Option obsługuje również standardowe właściwości i zdarzenia .
Powiązane strony
Odniesienie HTML: tag HTML <option>