javascript jQuery UI DatePicker - 禁用除每个月的第一天和第 15 天之外的所有日子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12061483/
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
jQuery UI DatePicker - Disable all days except first and 15th day of each month
提问by Chris
I want to disable all days on this datepicker except the 1st and 15th of every month. I referenced this answered question, but I am only able to return one date. I'm a novice in javascript. jQuery UI DatePicker - Disable all days except last day of month
我想禁用这个日期选择器上的所有日子,除了每个月的 1 日和 15 日。我参考了这个已回答的问题,但我只能返回一个日期。我是 javascript 新手。jQuery UI DatePicker - 禁用除每月最后一天以外的所有日期
Any help would be great, thank you.
任何帮助都会很棒,谢谢。
回答by gaffleck
This should do the trick:
这应该可以解决问题:
$(function(){
$("input").datepicker(
{
beforeShowDay: function (date) {
if (date.getDate() == 15 || date.getDate() == 1) {
return [true, ''];
}
return [false, ''];
}
});
});
? Check out the link below for a working example!
? 查看下面的链接以获取工作示例!
回答by Kaizen Programmer
Seems like this would work
似乎这会起作用
$('.selector').datepicker({
beforeShowDay: function (date) {
//getDate() returns the day (0-31)
if (date.getDate() == 1 || date.getDate() == 15) {
return [true, ''];
}
return [false, ''];
}
});