twitter-bootstrap 通过 Eternicode 在 Bootstrap datepicker 上设置开始日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38794955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set start date on Bootstrap datepicker by Eternicode
提问by Daniel Bonnell
Is it possible to specify the date during initialization using the Eternicode Bootstrap Datepicker? By default, when initializing the picker, the current date will be selected. I want a different date (in the future) to be selected. Is this possible and how so?
是否可以使用 Eternicode Bootstrap Datepicker 在初始化期间指定日期?默认情况下,初始化选择器时,将选择当前日期。我想选择一个不同的日期(在未来)。这可能吗?怎么可能?
Here is my initialization code:
这是我的初始化代码:
datePicker = detePickerElem.datepicker({
format: 'mm/dd/yyyy',
maxViewMode: 'months',
startDate: new Date(),
todayBtn: true,
todayHighlight: true,
weekStart: 1
});
datePicker.datepicker('setDate', new Date(futureDateObject));
I've tried using the setDatemethod to set the date after initialization, but this doesn't do anything. Note that for various reasons I'm using an older release (v1.3) of the project and am not able to migrate to a newer release, however I can fork the repo and modify the source if needed.
我尝试使用该setDate方法在初始化后设置日期,但这没有任何作用。请注意,由于各种原因,我使用的是该项目的旧版本 (v1.3),并且无法迁移到新版本,但是如果需要,我可以分叉 repo 并修改源。
回答by Pavithra Olety
Since you mentioned you are using eternicode Bootstrap datepicker, if you look at the options on https://github.com/eternicode/bootstrap-datepicker/blob/ca11c450/README.md#optionsthere is a way to set a custom startdate as below:
由于您提到您使用的是 eternicode Bootstrap datepicker,如果您查看https://github.com/eternicode/bootstrap-datepicker/blob/ca11c450/README.md#options上的选项,则有一种方法可以将自定义开始日期设置为以下:
$('#datepicker').datepicker('setStartDate', '2015-01-01');
Another thread that might be of help here its shown how to increment by 1 day: Bootstrap DatePicker, how to set the start date for tomorrow?
另一个可能有帮助的线程显示了如何增加 1 天:Bootstrap DatePicker,如何设置明天的开始日期?

