所以我在预订表格上使用此功能。该表格至少需要2天填写到今天的日期,这意味着您不能在不到2天的时间内提交预订。
$(function () {
$('#datepicker').Zebra_DatePicker({
direction: [2, false],
disabled_dates: ['* * * 0,6'],
first_day_of_week : 0
});
});
今天是周一至周四,这一切都很好。如果是星期五 - 2天的方向允许用户选择星期一(因为它将星期六+星期日的残疾计算为天),但我们需要2个工作日而不是简单的2天。
任何人都可以有任何指导或解决方法吗?
答案 0 :(得分:0)
我最终将自己的功能整合在一起。欢迎反馈:)
/*
==================================================================================================
BookingForm - Datepicker
==================================================================================================
*/
$(function () {
$('#datepicker').Zebra_DatePicker({
direction: [nextWorkingDay(), false],
disabled_dates: ['* * * 0,6'],
first_day_of_week : 0
});
});
这是调用下一个工作日函数的日期选择代码
/* This function ensures that there is at least 2 working
days before they are able to select a date. Without it
calling 2 days buffer in Zebra would include weekends meaning
you could lob on Saturday and request Monday - needs to be Tuesday at earliest.
*/
function nextWorkingDay() {
var today = new Date();
var dd = today.getDate();
//var mm = today.getMonth();
var month=new Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
var MMM = month[today.getMonth()];
var yyyy = today.getFullYear();
var theDate = dd+'-'+MMM+'-'+yyyy;
//All vars captured to do with todays date
//Step through finding weekends
var startDate = theDate; //"9-DEC-2011"
startDate = new Date(startDate.replace(/-/g, "/"));
var endDate = "", noOfDaysToAdd = 2, count = 0;
while(count < noOfDaysToAdd){
endDate = new Date(startDate.setDate(startDate.getDate() + 1));
if(endDate.getDay() != 0 && endDate.getDay() != 6){
count++;
}
}
// Weekend found OR not found + 2 day buffer added to the date
// Convert new date into bits + add padding to the month for Zebra usage
var nextDate = new Date(endDate);
var theDay = ("0" + (nextDate.getDate() + 1)).slice(-2); //Add padding to day
var theMonth = ("0" + (nextDate.getMonth() + 1)).slice(-2); //Add padding to month
var theYear = nextDate.getFullYear();
//Format as required by Zebra
var actualStart = theDay+'-'+theMonth+'-'+theYear;
return (actualStart);
}