作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Eternicode's fork of the bootstrap-datepicker library到目前为止,生成它一切顺利,但我想获取日期以便在更改日期后在我的逻辑中使用它。
$('#calendar').on('changeDate', function(event, date) {
// how to pop alert message to print the date I've chosen ?
});
我该怎么做?
最佳答案
作为described in the docs ,bootstrap-datepicker 的 Eternicode 版本向 changeDate
事件添加了三个属性,可用于访问新选择的日期。您将对 .date
属性(它指向代表所选日期的实际 date object)或 .format
方法感兴趣,您可以使用它来获取字符串形式的日期。
假设最简单的情况(您有一个选择器,并且您希望以与初始化日期选择器相同的格式将日期作为字符串获取),您只想调用 .format()
没有参数:
$('#calendar').on('changeDate', function(event) {
alert(event.format());
});
这里有一个 JSFiddle 展示了这个 Action :http://jsfiddle.net/bhm7p/3/
关于javascript - 如何从 bootstrap-datepicker 获取更改的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20413777/
我是一名优秀的程序员,十分优秀!