jQuery bootstrap-datetimepicker change event

我们两清 提交于 2019-12-18 12:48:01

问题


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

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

Anyone knows how to get new date value on change event ?


回答1:


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); })



回答2:


Please use this code to get change event of datetimepicker:

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



回答3:


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 :)



来源:https://stackoverflow.com/questions/31858920/jquery-bootstrap-datetimepicker-change-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!