且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Twitter Bootstrap 日期选择器:如何仅启用特定日期范围

更新时间:2023-01-28 15:51:10

您链接到的类似问题最终使用了相当多的技巧,但您想要的要简单得多——您正在寻找 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.