jquery ui Datepicker 指定日期不可选

狄玮
2023-12-01

jquery ui Datepicker 指定日期不可选,直接上代码。

//不可选日期列表
var disabledDays =['2021-12-29','2021-12-30','2021-12-31','2022-01-01','2022-01-02','2022-01-03'];

$( "#from_time" ).datepicker({
	autoSize: true,
	dateFormat: "yy-mm-dd",
	monthNames:  ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
	dayNamesMin: ["日", "一", "二", "叁", "肆", "伍", "陆"],
	duration: "slow",
	gotoCurrent: true,
	minDate: new Date(),
	navigationAsDateFormat: true,
	showMonthAfterYear: true,
	beforeShowDay:disableSpecificDays
	/*beforeShowDay: function(in_date) {
		var dateText = in_date.getFullYear()  + '-'+ (in_date.getMonth() + 1) + '-' + in_date.getDate();
        if($.inArray(dateText, disabledDays)!=-1){
            return [false];
        }
        return [true];
    }*/


});

function disableSpecificDays(date) {
    var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
    if (typeof(disabledDays) != "undefined") {
        for (var i = 0; i < disabledDays.length; i++) {
            if($.inArray(y + '-' + (m+1) + '-' +d ,disabledDays) != -1) {
                return [false,'class-store-closed', ''];
            }
        }
    }
    return [true];
}


// CSS style
.class-store-closed {
可以为不可选日期设置样式
}

 类似资料: