简体   繁体   中英

How to hide the Bootstrap datepicker

I made the date field readonly but still we are able to select the date from datepicker. I tried

$('#date').datepicker("None");
$('#date').datepicker("disable");
$('#date').datepicker("destroy");

None of them works. But the below code worked partially. Like on click it is showing the calendar and getting hidden. I'm not able to select any date from the calendar. This is fine but even it should not show the calendar.

$('#date').on('click', function(){
    $('.datepicker').hide();
});

If the #date is readonly, why initialize the datepicker? The following code should be enough: $('#date').attr('readonly', true)

EDITED to include the following solution to remove datepicker once it was initialized: $('#date').datepicker('remove');

你有没有尝试过

$('#date').hide();

Check the JSFiddle :- JSFiddle

$('.myDatepicker').each(function() {
var $picker = $(this);
$picker.datepicker();

var pickerObject = $picker.data('datepicker');

//HIDE THE CALENDER
$picker.on('changeDate', function(ev){
    $picker.datepicker('hide');
});
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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