简体   繁体   English

如何设置bootstrap-datepicker的日期?

[英]How to set the date of bootstrap-datepicker?

I've set up this JSFiddle showing my problem. 我已经设置了这个 JSFiddle来显示我的问题。

$('#dp3').datepicker();
var date = new Date('2009-05-05');
$('#dp3').datepicker('setDate', date);

It seems like a rather simple thing to do, and I feel I may be overlooking something, but this should work, shouldn't it? 这似乎是一件相当简单的事情,我觉得我可能会忽略某些事情,但这应该可行,不是吗? I'm simply trying to set the date of the calendar to a specific day. 我只是想将日历的日期设置为特定日期。

I know there are methods to use to set the start date in the HTML mark-up, but this is not what I need to do. 我知道可以使用一些方法来设置HTML标记中的开始日期,但这不是我需要做的。 This needs to be done in JavaScript. 这需要用JavaScript完成。

There's documentation here that I looked over, but the "setDate" option doesn't seem to do as it says it does. 在这里查看了一些文档,但是“ setDate”选项似乎并没有实现。

Thanks. 谢谢。

Try $('#dp3').datepicker('setValue', date); 尝试$('#dp3').datepicker('setValue', date); or $('#dp3').datepicker('update', date); $('#dp3').datepicker('update', date);

Try this... 尝试这个...

$(document).ready(function(){
    $('#dp3').datepicker();
    var date = new Date('2009-05-05');
    $('#dp3').datepicker('setDate', date);
});

See you DEMO 看你DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM