본문 바로가기
Coding/JavaScript

[JavaScript & jQuery] datepicker 특정 날짜 비활성화(disable) 시키는 방법 !!

by 포스트it 2023. 1. 4.
728x90
반응형

 

[JavaScript & jQuery] datepicker 특정 날짜 비활성화(disable) 시키는 방법 !!

 

$('#datepicker').datepicker({
    showOtherMonths: true,
    showMonthAfterYear: true,
    changeMonth: true,
    yearSuffix: '년',
    monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
    dayNamesMin: ['일', '월', '화', '수', '목', '금', '토'],
    defaultDate: null,
    beforeShowDay: disableWeekends, // 아래에 원하는 함수 사용하시면 됩니다.
}).datepicker;

 
// 주말만 막기(토, 일 disable)
function disableWeekends(date) {
    var noWeekend = jQuery.datepicker.noWeekends(date);
    return noWeekend[0] ? [true] : noWeekend;
}


// 특정 요일 막기
// 일요일(0), 월요일(1), 화요일(2), 수요일(3), 목요일(4), 금요일(5), 토요일(6)
function disableDay(date) {
  return [date.getDay() != 0, ''];
}


// 특정일 막기
let Days = ["2023-1-5","2023-1-10","2023-1-25"];
function disableDays(date) {
    var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
    for (i = 0; i < Days.length; i++) {
        if($.inArray(y + '-' +(m+1) + '-' + d,Days) != -1) {
            return [false];
        }
    }
    return [true];
}
728x90
반응형

댓글