Twitter Bootstrap 日期选择器:如何仅启用特定日期范围 [英] Twitter Bootstrap datepicker: how to enable only specific daterange

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

问题描述

我正在开发一些基于 Twitter Bootstrap 的项目,该项目使用来自 https://github 的日期选择器.com/eternicode/bootstrap-datepicker(这是其他版本的一个分支),但它缺少我需要的一个非常重要的功能 - 如何仅启用特定日期范围(例如,从过去 15 天到今天),因此甚至无法选择任何其他日期(不可点击).

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).

我在 SO 上找到了一个类似的解决方案,它禁用了周六和周日:将 bootstrap-datepicker 限制为仅限工作日?http://jsfiddle.net/katowulf/zNbUT/5/ ,但我不知道如何根据我的需要进行调整.

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.

提前致谢.

推荐答案

您链接到的类似问题最终使用了相当多的技巧,但您想要的要简单得多——您正在寻找 startDateendDate 选项:

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
});

这些选项可以采用 Date 对象、timedelta 字符串(就像我在这里所做的那样)或遵循给定 format 的日期字符串.

These options can take Date objects, timedelta strings (as I did here), or date strings following the given format.

演示:http://jsfiddle.net/zNbUT/131/

另外,请确保您使用的是来自 github 的代码——eyecon.ro 的副本是原始代码,带有旧的错误并且没有更新的功能.

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 日期选择器:如何仅启用特定日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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