자바스크립트로 체크박스가 체크되어 있는지 확인하기 위한 코드는 다음과 같습니다 -
예시
<!DOCTYPE html>
<html>
<head>
<h1>Displaying textBox when a checkbox is checked</h1>
Checkbox: <input type="checkbox" class="check" onclick="checkFunction()" />
<h2 class="textBox" style="display:none">Checkbox is checked!!!</h2>
<script>
document.querySelector(".check").addEventListener("click", checkFunction);
function checkFunction() {
var checkBox = document.querySelector(".check");
var textBox = document.querySelector(".textBox");
if (checkBox.checked == true) {
textBox.style.display = "block";
} else {
textBox.style.display = "none";
}
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

확인란을 클릭하면 -
