限制引导日期戳到平日? [英] Limit bootstrap-datepicker to weekdays only?
问题描述
有没有允许在下面发现的引导日期选择器中只允许工作日选择?
https://github.com/eternicode/bootstrap-datepicker/
Is there anyway to allow only weekday selections in the bootstrap date picker found below? https://github.com/eternicode/bootstrap-datepicker/
我正在实例化日期选择器,如下所示:
I'm instantiating the date picker like this:
$('#datepicker').datepicker();
/* Update datepicker plugin so that MM/DD/YYYY format is used. */
$.extend($.fn.datepicker.defaults, {
parse: function (string) {
var matches;
if ((matches = string.match(/^(\d{2,2})\/(\d{2,2})\/(\d{4,4})$/))) {
return new Date(matches[3], matches[1] - 1, matches[2]);
} else {
return null;
}
},
format: function (date) {
var
month = (date.getMonth() + 1).toString(),
dom = date.getDate().toString();
if (month.length === 1) {
month = "0" + month;
}
if (dom.length === 1) {
dom = "0" + dom;
}
return month + "/" + dom + "/" + date.getFullYear();
}
});
感谢任何帮助。
推荐答案
https://github.com/eternicode/bootstrap- datepicker 已经有一个选项来禁用特定工作日的选择。从文档:
The latest version from https://github.com/eternicode/bootstrap-datepicker already has an option to disable selection of particular weekdays. From the docs:
daysOfWeekDisabled
String,Array。默认值:'',[]
daysOfWeekDisabled
String, Array. Default: ‘’, []
应该禁用的星期几。值为0(星期日)至6(星期六)。多个值应以逗号分隔。示例:禁用周末:'0,6'
或 [0,6]
。
Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: '0,6'
or [0,6]
.
换句话说,只需要像这样实例化你的datepicker:
In other words, just instantiate your datepicker like this:
$('#datepicker').datepicker({
daysOfWeekDisabled: [0,6]
});
这是一个jsfiddle演示: http://jsfiddle.net/vj77M/1/
Here's a jsfiddle demonstrating this: http://jsfiddle.net/vj77M/1/
这篇关于限制引导日期戳到平日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!