0

我在我的 Rails 应用程序中使用https://github.com/TrevorS/bootstrap3-datetimepicker-rails datetimepicker。单击今天按钮后,我们如何关闭小部件?

$(document).on('turbolinks:load', () => {

  $(".form_datetime").datetimepicker({
    timeZone: 'utc',
    format: "YYYY-MM-DD HH:mm:ss UTCZ",
    defaultDate: moment().tz('UTC'),
    icons: {
      today: 'todayText',
      up: 'glyphicon glyphicon-chevron-up',
      up: "fa fa-arrow-up",
      down: "fa fa-arrow-down",
      previous: " fa fa-arrow-left",
      next: "fa fa-arrow-right"
    },
    showTodayButton: true,
    ignoreReadonly: true,
    allowInputToggle: true,
    useCurrent: true,
  });
4

1 回答 1

1

监听dp.change事件,通过锚元素的 data 属性访问日期选择器,然后调用 hide 函数。

$(document).on("dp.change", () => {
    $(".form_datetime").data("DateTimePicker").hide()
})

文档来源:

于 2019-09-13T01:53:26.387 回答