Obiekt pola wyboru danych wejściowych HTML DOM
Wprowadź obiekt pola wyboru
Obiekt Input Checkbox reprezentuje element HTML <input> z typem="checkbox".
Uzyskaj dostęp do wejściowego obiektu pola wyboru
Możesz uzyskać dostęp do elementu <input> z type="checkbox" za pomocą getElementById():
Przykład
var x = document.getElementById("myCheck");
Wskazówka: możesz również uzyskać dostęp do <input type="checkbox">, przeszukując kolekcję elementów formularza.
Utwórz wejściowy obiekt pola wyboru
Możesz utworzyć element <input> z type="checkbox" za pomocą metody document.createElement():
Przykład
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
Wejściowe pole wyboru Właściwości obiektu
Property | Description |
---|---|
autofocus | Sets or returns whether a checkbox should automatically get focus when the page loads |
checked | Sets or returns the checked state of a checkbox |
defaultChecked | Returns the default value of the checked attribute |
defaultValue | Sets or returns the default value of a checkbox |
disabled | Sets or returns whether a checkbox is disabled, or not |
form | Returns a reference to the form that contains the checkbox |
indeterminate | Sets or returns the indeterminate state of the checkbox |
name | Sets or returns the value of the name attribute of a checkbox |
required | Sets or returns whether the checkbox must be checked before submitting a form |
type | Returns which type of form element the checkbox is |
value | Sets or returns the value of the value attribute of a checkbox |
Standardowe właściwości i zdarzenia
Obiekt Input Checkbox obsługuje również standardowe właściwości i zdarzenia .
Powiązane strony
Samouczek HTML: formularze HTML
Odniesienie HTML: tag HTML <input>
Odniesienie HTML: atrybut typu HTML <input>