简体   繁体   English

如何隐藏Bootstrap日期选择器

[英]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? 如果#date是只读的,为什么还要初始化datepicker? The following code should be enough: $('#date').attr('readonly', true) 以下代码就足够了: $('#date').attr('readonly', true)

EDITED to include the following solution to remove datepicker once it was initialized: $('#date').datepicker('remove'); 编辑以包括以下解决方案,以便在初始化日期选择器后将其删除: $('#date').datepicker('remove');

你有没有尝试过

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

Check the JSFiddle :- JSFiddle 检查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');
});
});

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

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