Bootstrap Datetimepicker on select event

半腔热情 提交于 2019-12-10 12:15:09

问题


How do I access a js function exampleFunction() when date is selected? I want to pass the date value there.

text_field_tag for datetimepicker (haml):

= text_field_tag 'start_day', class: 'datepick'

Javascript:

$(".datepick").datetimepicker({
  timepicker: false,
  format: 'd/m/Y',
  closeOnDateSelect: true
});

回答1:


If this is the plugin you are using then it would be Like this.

$(".datepick").datetimepicker({
  onChangeDateTime:exampleFunction
});
function exampleFunction(){
  console.log("Date Selected")
}

For full option list Reference: http://xdsoft.net/jqplugins/datetimepicker/

Hope it helps.




回答2:


You can achieve this by using below given code:

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

I your case, it should be :

$(".datepick").on("dp.change",function(e){ exampleFunction(e.date)  });

Remember this will call the example function on change in value of each datetimepicker, since you used class.

Reference URL: https://eonasdan.github.io/bootstrap-datetimepicker/




回答3:


Try this :

$(".datepick").datetimepicker({
  timepicker: false,
  format: 'd/m/Y',
  closeOnDateSelect: true
}).on('dp.change', function (ev) {
    exampleFunction() ;//your function call
});



回答4:


Simply:

$(".datepick").datetimepicker({
  format: 'd/m/Y',
}).on('select', function (e) {
        console.log('on select event');
    });


来源:https://stackoverflow.com/questions/36127937/bootstrap-datetimepicker-on-select-event

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