gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:04:54 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com