Twitter Bootstrap datepicker:如何只启用特定的daterange [英] Twitter Bootstrap datepicker: how to enable only specific daterange
问题描述
我在SO上找到了一个类似的解决方案,它会禁用星期六和星期日:
仅限引导日期戳到工作日?
http://jsfiddle.net/katowulf/zNbUT/5/ ,但我不知道如何根据自己的需要进行调整。
提前感谢
您所链接的类似问题最终会使用相当的黑客,但是你赢了t要简单得多 - 您正在寻找 startDate
和 endDate
选项:
$('#dp1')。datepicker({
格式:'mm-dd-yyyy',
startDate:' -15d',
endDate:'+ 0d'//没有方便的现在符号
});
这些选项可以采用 Date
objects,timedelta字符串(如我在这里),或遵循给定的格式的日期字符串
。
演示: http://jsfiddle.net/zNbUT/131/
另外,请确保您使用github的代码 - eyecon.ro的副本是原始代码,旧的错误,没有较新的功能。
I am working on some project based on Twitter Bootstrap which using a datepicker from https://github.com/eternicode/bootstrap-datepicker (that is a fork from some other version), but it's missing a very important feature that I need - how to enable only specific date range (eg. from past 15 days till today), so any other date can't be even selected (not clickable).
I found a similar solution here on SO, which disables Saturdays and Sundays: Limit Bootstrap Datepicker to weekdays only? http://jsfiddle.net/katowulf/zNbUT/5/ , but I dont know how to adjust it to my needs.
Thanks in advance.
The similar question you linked to ended up using quite a hack, but what you want is a lot simpler -- you're looking for the startDate
and endDate
options:
$('#dp1').datepicker({
format: 'mm-dd-yyyy',
startDate: '-15d',
endDate: '+0d' // there's no convenient "right now" notation yet
});
These options can take Date
objects, timedelta strings (as I did here), or date strings following the given format
.
Demo: http://jsfiddle.net/zNbUT/131/
Also, make sure you're using the code from github -- eyecon.ro's copy is the original code, with old bugs and without the newer features.
这篇关于Twitter Bootstrap datepicker:如何只启用特定的daterange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!