twitter-bootstrap Bootstrap 日期选择器默认日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18329789/
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
Bootstrap datepicker default date
提问by Jess
I'm using Bootstrap datepicker and I'd like to make that when datepicker shows, default date would be set after 14 days from today. I've got this code but it doesn't work, default date is still set to today. Could anyone explain what am I missing? Thanks in advance.
我正在使用 Bootstrap datepicker,我想在 datepicker 显示时设置默认日期,从今天起 14 天后。我有这个代码但它不起作用,默认日期仍然设置为今天。谁能解释我错过了什么?提前致谢。
JS:
JS:
var plus14days = new Date();
plus14days.setDate(plus14days.getDate() + 14 );
$(".datepicker").datepicker("setValue", plus14days);
回答by Praveen
The code you've used is right.
您使用的代码是正确的。
The date will be displayed in textbox, but not in datepicker calendarlike this
日期将显示在textbox,但不是在日期选择日历这样的


To enable this feature you need to update it using the following code:
要启用此功能,您需要使用以下代码对其进行更新:
$(".datepicker").datepicker('update');
Now it looks like
现在看起来像


Check this in JSFiddle
在JSFiddle 中检查这个
回答by Luca Trazzi
Just a consideration, api changed setValue to setDate (http://bootstrap-datepicker.readthedocs.org/en/release/methods.html#setdate)
只是一个考虑,api 将 setValue 更改为 setDate ( http://bootstrap-datepicker.readthedocs.org/en/release/methods.html#setdate)

