Gewusst wie: Text anzeigen, wenn das Kontrollkästchen aktiviert ist
Überprüfen Sie, ob ein Kontrollkästchen mit JavaScript aktiviert ist.
Text anzeigen, wenn das Kontrollkästchen aktiviert ist:
Kontrollkästchen:Überprüfen Sie, ob ein Kontrollkästchen aktiviert ist
Schritt 1) HTML hinzufügen:
Beispiel
Checkbox: <input type="checkbox" id="myCheck" onclick="myFunction()">
<p id="text" style="display:none">Checkbox is CHECKED!</p>
Schritt 2) JavaScript hinzufügen:
Beispiel
function myFunction() {
// Get the checkbox
var checkBox =
document.getElementById("myCheck");
// Get the output text
var text = document.getElementById("text");
// If the checkbox
is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}