偶然的你
有beforeShowDay选项,该选项接受对每个日期调用的函数,如果允许日期返回true,如果不允许返回false。从医生那里:前展日函数以日期作为参数,必须返回一个数组,其[0]等于true/false,指示此日期是否可选1等于默认表示的CSS类名或“。它是在数据报警器显示之前的每一天调用的。在“数据录音机”中显示一些国定假日。$(".selector").datepicker({ beforeShowDay: nationalDays}) natDays = [
[1, 26, 'au'], [2, 6, 'nz'], [3, 17, 'ie'],
[4, 27, 'za'], [5, 25, 'ar'], [6, 6, 'se'],
[7, 4, 'us'], [8, 17, 'id'], [9, 7, 'br'],
[10, 1, 'cn'], [11, 22, 'lb'], [12, 12, 'ke']];function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1
&& date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];}一个内置的函数存在,称为“noWeekend”,它阻止了周末的选择。$(".selector").datepicker({ beforeShowDay: $.datepicker.noWeekends })要将两者结合起来,您可以做类似的事情(假设nationalDays(上述职能):$(".selector").datepicker({ beforeShowDay: noWeekendsOrHolidays}) function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return nationalDays(date);
} else {
return noWeekend;
}}更新:注意,在jQueryUI 1.8.19中,展前选择还接受可选的第三个参数,弹出工具提示。
翻过高山走不出你
这些答案非常有用。谢谢。我在下面的贡献中添加了一个数组,其中多天可以返回false(我们每周二、周三和周四都关闭)。我把具体的日期、年份和无周末的活动捆绑在一起。如果你想周末休息,把[星期六],[星期日]添加到关闭日期数组中。$(document).ready(function(){
$("#datepicker").datepicker({
beforeShowDay: nonWorkingDates,
numberOfMonths: 1,
minDate: '05/01/09',
maxDate: '+2M',
firstDay: 1
});
function nonWorkingDates(date){
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
var closedDates = [[7, 29, 2009], [8, 25, 2010]];
var closedDays = [[Monday], [Tuesday]];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false];
}
}
for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}
return [true];
}});