jQuery bootstrap-datetimepicker 更改事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31858920/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:49:57  来源:igfitidea点击:

jQuery bootstrap-datetimepicker change event

jqueryonchangebootstrap-datetimepicker

提问by user5198552

I am using bootstrap-datetimepicker plugin from Jonathan Petersonon my project.

我在我的项目中使用了 Jonathan Peterson 的 bootstrap-datetimepicker 插件

I'm having a problem with change event:

我在更改事件时遇到问题:

If I define event like this :

如果我这样定义事件:

$('#Release').on('dp.change', function(e){ console.log(e.date()); })

I get the error :

我收到错误:

Uncaught TypeError: e.date is not a function

未捕获的类型错误:e.date 不是函数

Anyone knows how to get new date valueon change event ?

任何人都知道如何在更改事件中获取新的日期值

回答by Kenneth Salomon

Looking at that link, it appears you are very close. You need to remove the parenthesis to get the right value.The way you currently are trying to log the value makes the browser think it needs to call a function.

查看该链接,您似乎非常接近。您需要删除括号以获得正确的值。您当前尝试记录该值的方式使浏览器认为它需要调用一个函数。

$('#Release').on('dp.change', function(e){ console.log(e.date); })

回答by Mohammed Jikriya

Please use this code to get change event of datetimepicker:

请使用此代码获取日期时间选择器的更改事件:

 $('.datepicker').datetimepicker(
    { format: 'MM/DD/YYYY' }).on('dp.change', function (e) {  });

回答by user5198552

Thanks to Kenneth suggestion, I figured out :

感谢肯尼斯的建议,我想通了:

$('#Release').on('dp.change', function(e){ 
    var formatedValue = e.date.format(e.date._f);
    console.log(formatedValue);
})

Thank you Kenneth :)

谢谢肯尼斯:)