HTML DOM 입력 체크박스 defaultChecked 속성은 HTML에서 체크박스의 checked 속성의 기본값을 반환합니다.
구문
다음은 구문입니다 -
object.defaultChecked
예시
defaultChecked 속성의 예를 살펴보겠습니다 -
<!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:180px;
margin:0.5rem;
border-radius:50px;
outline:none;
font-weight:bold;
}
.show-msg{
color:#db133a;
font-size:1.5rem;
font-weight:bold;
}
</style>
</head>
<body>
<h1>checked Property Example</h1>
<p>Are you smart?</p>
<input type="checkbox" checked>
<br>
<button onclick="check()">Lets Check? Click me</button>
<div class="show-msg"></div>
<script>
function check() {
var input = document.querySelector("input");
var showMsg = document.querySelector(".show-msg");
if(input.defaultChecked === true){
showMsg.innerHTML="You are right!You are smart by default";
} else {
showMsg.innerHTML="Hmmmmm!You are not smart by default";
}
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"확인하시겠습니까? 저를 클릭하세요 ” 버튼을 눌러 확인란이 기본적으로 선택되어 있는지 여부를 확인하시겠습니까?
