【问题标题】:Bootstrap datepicker close function引导日期选择器关闭功能
【发布时间】:2016-09-28 07:32:36
【问题描述】:

当用户在日历之外单击时,我正在尝试在引导日期选择器上进行函数调用。

当用户选择日期时 datepicker 自动关闭,当用户在 datepicker div 之外单击时,它会自行关闭。

所以我的问题是如何理解它何时关闭?我知道有一个名为 onClose 的事件,但它仅在页面加载时有效

fiddle

【问题讨论】:

    标签: javascript jquery twitter-bootstrap datepicker


    【解决方案1】:

    使用.on("hide"... 事件。

    来自文档:

    $('.datepicker').datepicker()
        .on(picker_event, function(e) {
        // `e` here contains the extra attributes
    });
    

    以您为例...picker_event 将是 hide
    比如:

    var checkin = $('#date-from').datepicker({
        format: 'dd/mm/yyyy',
        startDate: '+1d',
        weekStart: 1,
        beforeShowDay: function(date) {
        return date.valueOf() >= now.valueOf();
    },
        autoclose: true
    }).on('changeDate', function(ev) {
        alert("changed");
    }).on('hide', function(ev) { // <-----------
        alert("hide");
    });
    

    【讨论】:

      【解决方案2】:

      根据此处的文档:https://bootstrap-datepicker.readthedocs.io/en/latest/events.html#hide

      $('.datepicker').datepicker()
          .on('hide', function(e) {
              // `e` here contains the extra attributes
          });
      

      或者

      $('.datepicker').datepicker()
          .on('hide', myFunction);
      

      然后创建myFunction

      function myFunction(e) {
          // whatever you want :)
      }
      

      这是您的示例,几乎没有修改 https://jsfiddle.net/mr3dxj5p/6/ 在这里您可以看到我只是将 changeDate 更改为 hide 以触发警报消息

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-20
        • 2013-09-05
        • 1970-01-01
        • 2012-12-08
        • 1970-01-01
        • 2014-04-26
        • 1970-01-01
        • 2012-10-10
        相关资源
        最近更新 更多