1

tempus dominus datetimepicker is working with ID like

input#datetimepicker4.form-control.datetimepicker-input data-target="#datetimepicker4" data-toggle="datetimepicker" type="text"


$('#datetimepicker4').datetimepicker({
    format: 'L'
});

and with CLASS like

input.datetimepicker.form-control.datetimepicker-input data-target=".datetimepicker" data-toggle="datetimepicker" type="text"

$('.datetimepicker').datetimepicker({
        format: 'L'
    });

But its working for only one instance, may be due to using data-target as well

Actually, there are multiple date fields on single form with dynamic IDs so can't use like this.

Is there a way to use it with CLASS and for multiple instances?

4

1 回答 1

0

Not sure why it doesn't work with class but you could try initializing individual instances in a loop like:

$('.datetimepicker').each(function(){
  $(this).datetimepicker({
      format: 'L'
  });
})

Note you have a different class in the commented out selector which is datetimepicker-input. Might be using wrong class altoghether

于 2019-07-30T20:33:43.950 回答