这段代码背后的想法是我想设置一些日期,这将在我的datepicker中被禁用。如果我以这种格式离开:beforeShowDay: editDays,
,它就可以了。但我想以这种格式离开:beforeShowDay: function(dt) {
并在那里调用函数editDays!但正如您在我的代码中看到的那样,它并不起作用。其实我不知道怎么称呼这个功能。你能帮我做这个工作吗?这是我的javascript代码:
$( document ).ready(function() {
var request = $.ajax({
type: "POST",
url: "./actions/ajax/actiongetallfreedays.php",
async: false
});
var freedays = $.parseJSON(request.responseText);
var disabledDates = [];
for(var i = 0; i < freedays.length; i++){
split = freedays[i].free_day.split("-");
disabledDates[i] = split[0]+"/"+split[1]+"/"+split[2];
}
function editDays(date) {
for (var i = 0; i < disabledDates.length; i++) {
if (new Date(disabledDates[i]).toString() == date.toString()) {
return [false];
}
}
return [true];
}
});
这是我的主要功能:
function initDatePicker(cls, minDate, maxDate, beforeshowday) {
beforeshowday = beforeshowday == "1" ? beforeshowday : "0";
$(cls).datepicker({
beforeShowDay: function(dt) {
if (beforeshowday == 0) {
return [dt.getDay() == 1 || dt.getDay() == 2 || dt.getDay() == 3 || dt.getDay() == 4 || dt.getDay() == 5, ""];
} else {
return [dt.getDay() == 0 || dt.getDay() == 6, ""];
}
editDays();
},
// beforeShowDay: editDays,
firstDay: 1,
minDate: minDate,
maxDate: maxDate,
dateFormat: "yy-mm-dd",
date: $(cls).val(),
current: $(cls).val(),
starts: 1,
onBeforeShow: function() {
$(cls).DatePickerSetDate($(cls).val(), true);
},
onChange: function(formated) {
$(cls).val(formated);
$(cls).DatePickerHide();
}
})
.attr("readonly", "readonly");
}
答案 0 :(得分:0)
函数editDays()
未被调用,因为无论如何都是从匿名函数返回
beforeShowDay: function(dt) {
if (beforeshowday == 0) {
return [dt.getDay() == 1 || dt.getDay() == 2 || dt.getDay() == 3 || dt.getDay() == 4 || dt.getDay() == 5, ""];
}
else {
return [dt.getDay() == 0 || dt.getDay() == 6, ""];
}
// actually should be calling editDays like this here, but it never reaches
return editDays(dt);
},