简体   繁体   English

Bootstrap Datepicker关闭功能

[英]Bootstrap datepicker close function

I am trying to make function call on bootstrap datepicker when user clicks outside of calendar. 当用户在日历之外单击时,我试图在引导日期选择器上进行函数调用。

When user selects date datepicker closes automatically, same when user clicks outside of the datepicker div, it closes itself. 当用户选择日期选择器自动关闭时,与用户在日期选择器div之外单击时相同,它也会自动关闭。

So my question is how can I understand when its closed? 因此,我的问题是如何了解它何时关闭? I know there is an event called onClose but it only works when page loads 我知道有一个名为onClose的事件,但仅在页面加载时有效

fiddle 小提琴

Use the .on("hide"... event. 使用.on("hide"...事件。

From the docs: 从文档:

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

For your example... picker_event will be hide . 对于您的示例, picker_event将是hide
Something like: 就像是:

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");
});

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

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

Or 要么

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

And then create myFunction 然后创建myFunction

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

Here is your example with little modify https://jsfiddle.net/mr3dxj5p/6/ here you can see I just change changeDate to hide to fire alert message 这是您的示例,仅需少量修改https://jsfiddle.net/mr3dxj5p/6/,在这里您可以看到我只是将changeDate更改为hide以触​​发警报消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM