我有 2 个我编写的函数(大部分是修改的),我需要将它们组合成一个函数。第一个函数在用户选择部门时调用,它执行回调以查找日期并将它们添加到数组中。第二个函数在 jQuery 日期选择器中阻止天数。我已经让被封锁的日子正常工作,我只是不知道如何结合这两个功能。我尝试了很多不同的方法,但似乎没有任何效果。
// load calendar buttons
$(document).ready(function(){
$("#Return_Date").datepicker( { beforeShowDay: nonWorkingDates, showOn: "both", numberOfMonths: 2, minDate: 0, maxDate: "364D", gotoCurrent: true, buttonImageOnly: true } );
$("#Depart_Date").datepicker( { beforeShowDay: nonWorkingDates, showOn: "both", numberOfMonths: 2, minDate: 0, maxDate: "364D", gotoCurrent: true, buttonImageOnly: true } );
});
// load blocked days - this loads properly into the date pickers above
function nonWorkingDates(date){
// create an array for closedDates
var closedDates = [[3,22,2012], [3,25,2012], [4,15,2012], [4,24,2012], [4,25,2012]];
//loop through the list of closed Dates
for (i = 0; i < closedDates.length; i++) {
// if the date is found set it as disabled. January is 0, February 1, etc so a -1 is needed on the month value
if (date.getMonth() == closedDates[i][0] - 1 && date.getDate() == closedDates[i][1] && date.getFullYear() == closedDates[i][2]) {
return [false];
}
}
return [true];
};
//load in closed dates i need the BlockedTravelDays array to pull into the date pickers. the array here loads fine
$(document).ready(function NoTravelDays() {
$("#TripApprovalDepartment").change(function() {
var value = $.trim($("#TripApprovalDepartment").val());
if (value.length > 0) {
$.getJSON("../approval.cfc?method=getBlockedDays&returnFormat=json", {DeptID:value}, function(res,code) {
// create an Array
var BlockedTravelDays = [];
for (var i = 0; i < res.DATA.length; i++) {
// store the travel days in the array
BlockedTravelDays.push(res.DATA[i][2]);
}; // end for loop
}); // end JSON
} // end if
});
});