Twitter Bootstrap datepicker:如何只启用特定的daterange [英] Twitter Bootstrap datepicker: how to enable only specific daterange

查看:119
本文介绍了Twitter Bootstrap datepicker:如何只启用特定的daterange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一些基于Twitter Bootstrap的项目,它使用 https://github.com/eternicode/bootstrap- datepicker (这是一些其他版本的分支),但它缺少一个非常重要的功能,我需要 - 如何只启用特定的日期范围(例如,从过去15天到今天),所以任何其他日期可以不要选择(不可点击)。



我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆