我的代码排除日期,为日期字段分配自定义类和标题。
var holidays =[ [2020,06,17,'A Holiday'],[2020,06,18,'Another Holiday'],[2020,06,19,'Some Other Holiday'] ];
function setHolidays(date) {
for (i = 0; i < holidays.length; i++) {
if (date.getFullYear() == holidays[i][0]
&& date.getMonth() == holidays[i][1] - 1
&& date.getDate() == holidays[i][2]) {
return [false, 'holiday', holidays[i][3]];
}
}
return [true, ''];
}
$( ".add_delivery_date").datepicker( {
minDate: 0,
firstDay: 0,
beforeShowDay: setHolidays
} );
我知道我可以通过使用以下来排除周末
beforeShowDay: $.datepicker.noWeekends
但我不确定如何将其添加到现有代码中。
你可以简单地传递noWeekends: true
.
$( ".add_delivery_date").datepicker( {
noWeekends: true,
minDate: 0,
firstDay: 0,
beforeShowDay: setHolidays
} );
这比我想象的要容易:
function setHolidays(date) {
for (i = 0; i < holidays.length; i++) {
if (date.getFullYear() == holidays[i][0]
&& date.getMonth() == holidays[i][1] - 1
&& date.getDate() == holidays[i][2]) {
return [false, 'holiday', holidays[i][3]];
}
}
var noWeekend = $.datepicker.noWeekends(date);
return !noWeekend[0] ? noWeekend : [true];
}