将 bootstrap-datepicker 限制在工作日? [英] 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. 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]
.
换句话说,只需像这样实例化您的日期选择器:
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/
这篇关于将 bootstrap-datepicker 限制在工作日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!