반응형
input type=month에 이전달과 다음달 넣기 버튼입니다.
<!DOCTYPE html>
<html>
<head>
<title>Month Picker with Buttons</title>
</head>
<body>
<button id="prevMonth">이전 월</button>
<input type="month" id="monthPicker">
<button id="nextMonth">다음 월</button>
<script>
const monthPicker = document.getElementById('monthPicker');
const prevMonth = document.getElementById('prevMonth');
const nextMonth = document.getElementById('nextMonth');
// 현재 날짜 설정
monthPicker.valueAsDate = new Date();
prevMonth.addEventListener('click', function() {
changeMonth(-1);
});
nextMonth.addEventListener('click', function() {
changeMonth(1);
});
function changeMonth(offset) {
let current = new Date(monthPicker.value);
current.setMonth(current.getMonth() + offset);
monthPicker.value = current.toISOString().slice(0, 7);
}
</script>
</body>
</html>
반응형