twitter-bootstrap Bootstrap Datepicker - 设置默认选择器日期,不显示值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30675100/
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 - Set default picker date, NOT display value
提问by Octopoid
I'm using Bootstrap-Datepicker, and it's working really well.
我正在使用 Bootstrap-Datepicker,它运行得非常好。
One of the fields I'm using it for is a date of birth, and I know what the approximate age of the applicants is going to be, so it makes sense for me to default the picker to showing January 2000.
我使用它的字段之一是出生日期,而且我知道申请人的大致年龄,因此我将选择器默认显示为 2000 年 1 月是有意义的。
However, the only way I've found of doing this is to select a date, which actually updates the field with a value, which I don't want.
但是,我发现这样做的唯一方法是选择一个日期,它实际上用我不想要的值更新字段。
$(document).ready(function () {
var datePickers = $('input[data-provide="datepicker"]');
datePickers.each(function () {
var datePicker = $(this);
datePicker.datepicker('setDate', new Date(2000, 1, 1));
});
});


Is there a method in the object to select the view date or similar?
对象中是否有选择查看日期或类似日期的方法?
This is the default view I'm looking for:
这是我正在寻找的默认视图:


(Apologies if this is a duplicate - I looked but only found questions about how to actually pick dates.)
(抱歉,如果这是重复的 - 我看了但只发现了有关如何实际选择日期的问题。)
回答by Tim Lewis
Here it is:
这里是:
$('.datepicker').datepicker({
defaultViewDate: {year:2000, month:0, day:1},
});
And the js Fiddle:
和 js 小提琴:
回答by N036
This works for me:
这对我有用:
$('input[data-provide="datepicker"]').data("date","2000-01-01");

