在jQuery UI datepicker上禁用一周中的特定日期 [英] Disable specific days of the week on jQuery UI datepicker
问题描述
我想禁用某些日子,如每周一或每周二或每周一,周四周五等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.
我试图在BeforeShowDay前玩,但这需要一个特定的日期。我只是想禁用一周中的整天。
I tried to play with beforeShowDay, but that requires a specific date. I just want to disable an entire day of the week.
更新:感谢您提出的解决方案,但它们都适用于特定日期。如果我想在整个一个星期一和星期二禁用每个星期一,该怎么办?我该怎么做?
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?
推荐答案
你可以将 beforeShowDate
选项的datepicker与 Date.getDay()
做你想要的,像这样:
You can ue the beforeShowDate
option of the datepicker combined with Date.getDay()
to do what you want, like this:
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 1 && day != 2)];
}
});
您可以看到工作演示这里,这只是采取日期,检查是否是星期一(1)或星期二(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.
这篇关于在jQuery UI datepicker上禁用一周中的特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!