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 datepicker上禁用某些日子,例如每个星期一或每个星期二或每个星期一,星期四,星期四等。
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?
更新:感谢您提供的建议解决方案,但它们都适用于特定日期。如果我想要禁用全年的每个星期一和星期二,该怎么办?我该怎么办?
1 个解决方案
#1
56
You can ue the beforeShowDate
option of 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),如果是这种情况,则返回第一个数组条目的假。
#1
56
You can ue the beforeShowDate
option of 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),如果是这种情况,则返回第一个数组条目的假。