HTML DOM 입력 월 defaultValue 속성은 HTML 문서에서 type=”month”의 입력 필드의 기본값을 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. 기본값 반환
object.defaultValue
2. 기본값 수정
object.defaultValue=value
여기서 값 문자열 형식의 모든 날짜(예:"2019-03")
예시
HTML DOM 입력 월 defaultValue 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)
center/cover no-repeat;
height:100%;
}
p{
font-weight:700;
font-size:1.2rem;
}
input{
width:35%;
border:2px solid #fff;
background-color:transparent;
color:#fff;
font-weight:bold;
padding:8px;
}
.btn{
background:#0197F6;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
.show{
font-size:1.5rem;
font-weight:bold;
}
</style>
</head>
<body>
<h1>DOM Input month defaultValue Example</h1>
<p>Hi, Enter your month of birth</p>
<input type="month" class="monthInput">
<button onclick="changeValue()" class="btn">Submit</button>
<div class="show"></div>
<script>
function changeValue() {
var monthInput = document.querySelector(".monthInput");
var showMsg = document.querySelector(".show");
monthInput.defaultValue = "1997-10";
monthInput.value= monthInput.defaultValue;
showMsg.innerHTML =":D hehe I changed your month of birth into mine!";
}
</script>
</body>
</html> 출력
이것은 다음 결과를 생성합니다 -

이제 생년월일을 입력하고 "제출을 클릭하십시오. " 버튼.


여기에서 선택한 월이 기본 월인 "1997년 10월"로 바뀌는 것을 볼 수 있습니다.