如何从bootstrap-datepicker获取更改日期

iKh*_*tib 1 javascript jquery twitter-bootstrap bootstrap-datepicker

我正在使用Eternicode的bootstrap-datepicker库的fork,直到现在一切都很顺利生成它,但是我希望得到日​​期以便在更改日期后在我的逻辑中使用它.

$('#calendar').on('changeDate', function(event, date) {
  // how to pop alert message to print the date I've chosen ?
});
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Mar*_*ery 13

文档中所述,Eternicode版本的bootstrap-datepicker为changeDate事件添加了三个属性,可用于访问新选择的日期.您将对.date属性(指向表示所选日期的实际日期对象)或.format方法感兴趣,您可以使用该方法将日期作为字符串.

假设最简单的情况(你有一个选择器,并且你希望以与初始化datepicker相同的格式获取日期作为字符串),你只需要调用.format()不带参数:

$('#calendar').on('changeDate', function(event) {
    alert(event.format());
});
Run Code Online (Sandbox Code Playgroud)

这是一个JSFiddle,显示了这个:http://jsfiddle.net/bhm7p/3/