首先,这不是通用的解决方案。我没有时间寻求通用解决方案。我的解决方案是,如果您必须在没有周末的情况下选择 5 天。
在 jquery-ui.multidatepicker.js 中 onSelect 方法(cca.81 行)添加:
if(this.multiDatesPicker.mode == 'daysRangeWithoutWeekends' && this.multiDatesPicker.dates.picked.length > 0){
var i = 0,
last
if(this.multiDatesPicker.dates.picked[0].getDay() == 2){ //thusday
i = 1
//remove sunday
all_removed_dates.push(this.multiDatesPicker.dates.picked[4])
}
if(this.multiDatesPicker.dates.picked[0].getDay() == 3){//wednesday
i = 2
//remove sunday and saturday
all_removed_dates.push(this.multiDatesPicker.dates.picked[3], this.multiDatesPicker.dates.picked[4])
}
if(this.multiDatesPicker.dates.picked[0].getDay() == 4){ //thursday
i=2
all_removed_dates.push(this.multiDatesPicker.dates.picked[2], this.multiDatesPicker.dates.picked[3])
}
if(this.multiDatesPicker.dates.picked[0].getDay() == 5){ //friday
i=2
all_removed_dates.push(this.multiDatesPicker.dates.picked[1], this.multiDatesPicker.dates.picked[2])
}
last = this.multiDatesPicker.dates.picked.pop()
this.multiDatesPicker.dates.picked.push(last)
if(this.multiDatesPicker.dates.picked[0].getDay() == 2){ //thusday
//if we have thusday we add 2 day after last day so last day in range was saturday and we add 2 day and we get date for monday
var new_date = new Date(last.getFullYear(), last.getMonth(), last.getDate() + 2)
all_new_dates.push(new_date)
}else{
//if there were sunday and saturday in range we add 2 days to last date in range
for(var j = 1; j <= i; j++){
var new_date = new Date(last.getFullYear(), last.getMonth(), last.getDate() + j)
all_new_dates.push(new_date)
}
}
var obj = this
//remove sunday and saturday
$.each(all_removed_dates, function(index, value) {
methods.removeDates.call(obj, value);
});
//add new days
$.each(all_new_dates, function(index, value) {
methods.add_new_date.call(obj,value);
});
}
在 jquery-ui.multidatepicker.js 中的 toogleDate 方法(cca。431 行)中,在 case 'daysRange' 之前添加:
case 'daysRangeWithoutWeekends':
在 jquery-ui.multidatepicker.js 中的 setMode(cca.473row) 之前 case 'daysRange' 添加:
case 'daysRangeWithoutWeekends':
砑光机初始化:
jQuery('#deliverydate').multiDatesPicker({
minDate:0,
beforeShowDay: noWeekendsOrHolidays,
mode: 'daysRangeWithoutWeekends',
autoselectRange: [0,5],
numberOfMonths: 2
});
如果有人制作通用算法,请分享它=)