确定minDate时排除beforeShowDay

问题描述

| 我正在使用beforeShowDay排除假日和周末,但是我希望在计算minDate时排除beforeShowDays。 例如。如果一周中的当前日期是星期五,而minDate是2,我希望将周末排除在等式之外。因此,我希望可以选择星期三,而不是选择第一天为星期一。 这是我的jQuery:
$( \"#date\" ).datepicker({
minDate: 2,maxDate: \"+12M\",// Date range
beforeShowDay: nonWorkingDates
});
有谁知道如何做到这一点?     

解决方法

这样的事情怎么样:
function includeDate(date) {
    return date.getDay() !== 6 && date.getDay() !== 0;
}

function getTomorrow(date) {
    return new Date(date.getFullYear(),date.getMonth(),date.getDate() + 1);
}

$(\"#date\").datepicker({
    beforeShowDay: function(date) {
        return [includeDate(date)];
    },minDate: (function(min) {
        var today = new Date();
        var nextAvailable = getTomorrow(today);
        var count = 0;
        var newMin = 0; // Modified \'min\' value

        while(count < min) {
            if (includeDate(nextAvailable)) {
                count++;
            }
            newMin++; // Increase the new minimum
            nextAvailable = getTomorrow(nextAvailable);            
        }
        return newMin;
    })(2) // Supply with the default minimum value.
});
基本上,利用您已经为
beforeShowDay
定义的方法,找出下一个有效日期在哪里。如果我的逻辑是正确的(并且您仅排除周末),则此值只能是2或4:2如果途中有周末(周四或周五),则为2。 如果您还有其他日子要排除在外,情况会变得更加复杂,但是我认为逻辑仍然遵循。 这是小提琴上的代码:http://jsfiddle.net/TpSLC/     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...