在 jQuery UI 日期选择器上禁用一周中的特定日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2968414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:37:52  来源:igfitidea点击:

Disable specific days of the week on jQuery UI datepicker

jqueryjquery-uidatepicker

提问by Amir

Possible Duplicate:
Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)?

可能的重复:
可以使 jQuery UI Datepicker 禁用星期六和星期日(和节假日)吗?

I would like to disable certain days like every monday or every tuesday or every monday, thursday friday, etc. on a jQuery UI datepicker.

我想在 jQuery UI 日期选择器上禁用某些日子,例如每个星期一或每个星期二或每个星期一、星期四、星期五等。

I tried to play with beforeShowDay, but that requires a specific date. I just want to disable an entire day of the week.

我尝试使用 beforeShowDay,但这需要一个特定的日期。我只想禁用一周中的一整天。

Update: Thanks for the suggested solutions, but they all work for specific dates. What if I wanted to disable every single Monday and Tuesday for the entire year. How would I do that?

更新:感谢建议的解决方案,但它们都适用于特定日期。如果我想禁用全年的每个星期一和星期二怎么办。我该怎么做?

回答by Nick Craver

You can ue the beforeShowDateoptionof the datepicker combined with Date.getDay()to do what you want, like this:

您可以结合使用datepicker 的beforeShowDate选项Date.getDay()来执行您想要的操作,如下所示:

?$("#datepicker").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 1 && day != 2)];
    }
})?????;?

You can see a working demo here, this just takes the date, checks if it's a Monday (1) or Tuesday (2) and returns false for the first array entry if that's the case.

你可以在这里看到一个工作演示,这只是获取日期,检查它是星期一 (1) 还是星期二 (2),如果是这种情况,则为第一个数组条目返回 false。