# input type=month 이전달, 다음달 넣기

- 주소: https://duotone.co.kr/entry/input-typemonth-%EC%9D%B4%EC%A0%84%EB%8B%AC-%EB%8B%A4%EC%9D%8C%EB%8B%AC-%EB%84%A3%EA%B8%B0
- 글쓴이: 서기㏇
- 카테고리: 개발·프로그래밍
- 작성일: 2024-01-10
- 태그: input, month, type, 다음달, 다음월, 이전달, 전월

input type=month에 이전달과 다음달 넣기 버튼입니다.

```

    Month Picker with Buttons

    이전 월

    다음 월

        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);
        }

```
