HTML-DOM - Eingabe-Kontrollkästchenobjekt
Checkbox-Objekt eingeben
Das Input Checkbox-Objekt repräsentiert ein HTML-<input>-Element mit type="checkbox".
Greifen Sie auf ein Eingabe-Kontrollkästchenobjekt zu
Sie können auf ein <input>-Element mit type="checkbox" zugreifen, indem Sie getElementById() verwenden:
Beispiel
var x = document.getElementById("myCheck");
Tipp: Sie können auch auf <input type="checkbox"> zugreifen, indem Sie die Elementsammlung eines Formulars durchsuchen .
Erstellen Sie ein Eingabe-Kontrollkästchen-Objekt
Sie können ein <input>-Element mit type="checkbox" erstellen, indem Sie die Methode document.createElement() verwenden:
Beispiel
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
Geben Sie die Objekteigenschaften des Kontrollkästchens ein
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 |
Standardeigenschaften und -ereignisse
Das Input Checkbox-Objekt unterstützt auch die Standardeigenschaften und -ereignisse .
Verwandte Seiten
HTML-Tutorial: HTML-Formulare
HTML-Referenz: HTML-<input>-Tag
HTML-Referenz: HTML-Attribut vom Typ <input>