HTML DOM Wybierz obiekt
Wybierz obiekt
Obiekt Select reprezentuje element HTML <select>.
Uzyskaj dostęp do wybranego obiektu
Możesz uzyskać dostęp do elementu <select> za pomocą getElementById():
Przykład
var x = document.getElementById("mySelect");
Porada: Możesz również uzyskać dostęp do obiektu Select, przeszukując kolekcję elementów formularza.
Utwórz wybrany obiekt
Możesz utworzyć element <select> za pomocą metody document.createElement():
Przykład
var x = document.createElement("SELECT");
Wybierz kolekcje obiektów
Collection | Description |
---|---|
options | Returns a collection of all the options in a drop-down list |
Wybierz właściwości obiektu
Property | Description |
---|---|
autofocus | Sets or returns whether a drop-down list should automatically get focus when the page loads |
disabled | Sets or returns whether the drop-down list is disabled, or not |
form | Returns a reference to the form that contains the drop-down list |
length | Returns the number of <option> elements in a drop-down list |
multiple | Sets or returns whether more than one option can be selected from the drop-down list |
name | Sets or returns the value of the name attribute of a drop-down list |
selectedIndex | Sets or returns the index of the selected option in a drop-down list |
size | Sets or returns the value of the size of a drop-down list |
type | Returns which type of form element a drop-down list is |
value | Sets or returns the value of the selected option in a drop-down list |
Wybierz metody obiektowe
Method | Description |
---|---|
add() | Adds an option to a drop-down list |
checkValidity() | |
remove() | Removes an option from a drop-down list |
Standardowe właściwości i zdarzenia
Obiekt Select obsługuje również standardowe właściwości i zdarzenia .
Powiązane strony
Samouczek HTML: formularze HTML
Odniesienie HTML: tag HTML <select>