我把自己的功能拼湊在一起。反饋是歡迎的。
/*
==================================================================================================
BookingForm - Datepicker
==================================================================================================
*/
$(function() {
$('#datepicker').Zebra_DatePicker({
direction: [nextWorkingDay(), false],
disabled_dates: ['* * * 0,6'],
first_day_of_week : 0
});
});
這個日期選擇器代碼調用nextWorkingDay功能
/* 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);
}