如何使用on change事件更改Date Time Picker启用的小时数?

时间:2020-06-12 03:32:12

标签: javascript jquery ruby-on-rails bootstrap-datetimepicker

我有以下选择器:

$('.datetimepicker').datetimepicker({
    format: 'LT',
    locale: 'PT-BR',
    icons: {
      up: "fa fa-chevron-up",
      down: "fa fa-chevron-down",
      time: "far fa-clock",
    },
    enabledHours: permittedHours(),
    stepping: 15,
  });

但是我想在输入值更改的情况下,在重新设置enabledHours时调用其他aux函数。

我将其链接起来,可以成功弹出警报:

$('.datetimepicker').datetimepicker({
    format: 'LT',
    locale: 'PT-BR',
    icons: {
      up: "fa fa-chevron-up",
      down: "fa fa-chevron-down",
      time: "far fa-clock",
    },
    enabledHours: permittedHours(),
    stepping: 15,
  })
  .on('dp.change', function (e) { 
    alert(e.date._i)
  });

但是,如果我尝试处理enabledHours,它将无法正常工作。在这种情况下,如何将新值传递给enabledHours?

1 个答案:

答案 0 :(得分:-1)

on('dp.change', function (e) {
     $('.datetimepicker').data("DateTimePicker").enabledHours(your_function(e.date.format('yourformat')));
});