0

我有一个禁用所有星期一、星期二、星期三和星期四的工作功能。它看起来像这样:

$("#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];
}

但我不知道如何将它与我现有的周一至周四功能结合起来。帮助?

4

1 回答 1

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];
    }
        }


});
  });
于 2013-10-03T09:22:02.690 回答