【问题标题】:Jquery UI Datepicker - Disable the first monday after a weekend if the current day is Saturday or SundayJquery UI Datepicker - 如果当前日期是星期六或星期日,则禁用周末后的第一个星期一
【发布时间】:2012-10-01 16:49:07
【问题描述】:

我有一个日期选择器,如果是星期六或星期日,我想禁用周末之后的星期一....这可能吗?

我猜我必须想办法:

  1. 查找当前日期(天)
  2. 如果是周六或周日,则使用条件语句禁用下周一。也许最简单的方法是有两个条件。因此,如果它的 Sat 然后在两天后禁用,如果它的 Sun 然后在 1 天后禁用???

对此非常感谢的任何帮助

【问题讨论】:

  • 所以您总是希望周六、周日和周一禁用?

标签: jquery-ui datepicker


【解决方案1】:

您可以通过创建一个新的日期对象来找到当前日期:

var today = new Date();

然后您可以使用datepickerbeforeShowDay 函数来禁用您在条件中描述的以下星期一:

这是我制作的一个工作小提琴:http://jsfiddle.net/MadLittleMods/DfAYY/

var today = new Date(); // Go ahead and change the current day (year, month, day)

// If today is Saturday or Sunday then no Monday for you
function noFollowingMonday(thisDate) {
    // Sunday = 0, Saturday = 6;
    if(today.getDay() == 0 || today.getDay() == 6)
    {
        // Monday = 1
        // Only Mondays - that are after today - and is the first monday after today
        if (thisDate.getDay() == 1 && today.getDate() < thisDate.getDate() && Math.abs(today.getDate() - thisDate.getDate()) < 7)
        {
            return [false, "", "Unavailable"];
        }
    }

    return [true, "", "Choose"];

}

$('#datepicker').datepicker({
    beforeShowDay: noFollowingMonday
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 2021-03-12
    • 2018-03-28
    相关资源
    最近更新 更多