禁用 jQuery UI 日历中的所有星期日
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4376987/
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
Disable all Sundays in jQuery UI Calendar
提问by Mohit Jain
I want to disable Sundays in jQuery UI calendar.
我想在 jQuery UI 日历中禁用星期日。
From docs I came to know about this:--
我从文档中了解到这一点:--
$('#datepicker').datepicker({ minDate: 4,beforeShowDay: $.datepicker.noWeekends });
This will disable Saturdays and Sundays both. But I want to diasble only Sunday. Is there any default option for this.
这将禁用周六和周日。但我只想在星期天禁用。是否有任何默认选项。
Bad way to solve it
不好的解决方法
beforeShowDay take true or false as params for every day. So write a function which returns true or false based upon each day.
beforeShowDay 将 true 或 false 作为每天的参数。所以写一个函数,根据每一天返回真或假。
回答by Bhanu Prakash Pandey
try this
尝试这个
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0), ''];
}
});
回答by Vijay Dhanvai
Yes you can disable Saturday and Sunday, In jQuery UI datepicker.
是的,您可以在 jQuery UI 日期选择器中禁用周六和周日。
https://codepen.io/VijayDhanvai/pen/ExjdGPb
https://codepen.io/VijayDhanvai/pen/ExjdGPb
$("#date").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0 && day != 6), ''];
}
});
回答by Nadeem Ijaz
you can also use this code it is working for me
您也可以使用此代码,它对我有用
$("#date").datepicker({
filter: function(date, view) {
if (date.getDay() === 0 && view === 'day') {
return false; // Disable all Sundays, but still leave months/years, whose first day is a Sunday, enabled.
}
}
});