HTML DOM 입력 확인란 checked 속성은 HTML에서 확인란의 checked 속성 값을 반환하고 변경합니다.
구문
다음은 구문입니다 -
1. 반송 확인
object.checked
2. 변경 확인
object.checked = true|false
예시
HTML DOM Input Checkbox checked 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM checked property</title>
<style>
body{
text-align:center;
}
p{
font-size:1.5rem;
color:#ff8741;
}
input{
width:30px;
height:30px;
}
button{
background-color:#db133a;
color:#fff;
padding:8px;
border:none;
width:120px;
margin:0.5rem;
border-radius:50px;
outline:none;
}
</style>
</head>
<body>
<h1>checked Property Example</h1>
<p>Are you happy?</p>
<input type="checkbox">
<br>
<button onclick="yes()">Yes</button>
<button onclick="no()">No</button>
<script>
function yes() {
document.querySelector("input").checked = true;
}
function no() {
document.querySelector("input").checked = false;
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"예" 버튼을 클릭하여 확인란을 선택합니다.

이제 "아니요를 클릭합니다. " 버튼을 눌러 확인란의 선택을 취소합니다.
