我有一个工作功能,可以禁用所有周一,周二,周三和周四。它看起来像这样:
$("#dateInput").datepicker({
minDate: 2,
maxDate: "+3M",
dateFormat: "DD, d MM, yy",
beforeShowDay: function(day) {
var day = day.getDay();
if (day == 1 || day == 2 || day == 3 || day == 4) {
return [false, ""]
}
else {
return [true, ""]
}
}
});
现在我需要的是也能够禁用特定日期,例如10月25日。我发现了一个可以自行运行的功能:
$("#dateInput").datepicker({
minDate: 2,
maxDate: "+3M",
dateFormat: "DD, d MM, yy",
beforeShowDay: disableAllTheseDays,
});
var disabledDays = ["10-25-2013"];
function disableAllTheseDays(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
return [false];
}
}
return [true];
}
但我不知道如何将它与我现有的星期一到星期四的功能结合起来。帮助
答案 0 :(得分:0)
在http://jsfiddle.net/devmgs/E9m8G/
进行演示$(function() {
$( "#datepicker" ).datepicker({
minDate: 2,
maxDate: "+3M",
dateFormat: "DD, d MM, yy",
beforeShowDay: function(day) {
var newday = day.getDay();
if (newday == 1 || newday == 2 || newday == 3 || newday == 4) {
return [false, ""]
}
else {
var disabledDays = ["10-25-2013"];
var m = day.getMonth(), d = day.getDate(), y = day.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
return [false];
}
}
return [true];
}
}
});
});