Bootstrap datepicker hide after selection

前端 未结 18 2616
暖寄归人
暖寄归人 2020-12-13 01:30

How do I hide the calendar after a date is selected? Is there a specific function that I can use? My code below:

$(\'#dp1\').datepicker({
    format: \'mm-d         


        
相关标签:
18条回答
  • 2020-12-13 01:42

    If it's any help to anyone, the Version 2.0 of the bootstrap datepicker no longer works with the accepted answer.

    Here's how I got it working on mine:

    $('yourpickerid').datepicker({
        format: 'dd/mm/yyyy',
    }).on('changeDate', function(e){
        $(this).datepicker('hide');
    });
    

    See http://bootstrap-datepicker.readthedocs.org/en/latest/events.html#changedate

    0 讨论(0)
  • 2020-12-13 01:43

    For datetime picker

    $('yourpickerid').datetimepicker({
            format: 'dd/mm/yyyy',
    }).on('changeDate', function(e){
            $(this).datetimepicker('hide');
    });
    
    0 讨论(0)
  • 2020-12-13 01:44

    If you're looking to override the behavior of the calendar in general, globally, try editing the Datepicker function (in my example it was line 82),

    from

        this.autoclose = false;
    

    to

        this.autoclose = true;
    

    Worked fine for me, as I wanted to have all my calendar instances behave the same.

    0 讨论(0)
  • 2020-12-13 01:44

    I got a perfect solution:

    $('#Date_of_Birth').datepicker().on('changeDate', function (e) {
        if(e.viewMode === 'days')
            $(this).blur();
    });
    
    0 讨论(0)
  • 2020-12-13 01:44

    Haven't seen this mentioned, but this is what fixed it for me:

    switchOnClick: true
    
    0 讨论(0)
  • 2020-12-13 01:46

    In bootstrap 4 use "autoHide : true"

    $('#datepicker1').datepicker({
        autoHide: true,
        format: 'mm-yyyy',
        endDate: new Date()
    });
    
    0 讨论(0)
提交回复
热议问题