动态重新初始化或销毁 Bootstrap 日期选择器 [英] Re-initialize or destroy Bootstrap datepicker dynamically
问题描述
有没有办法破坏 Bootstrap 日期选择器动态更新其选项,如格式、beforeShowDay 等?我知道 jQuery UI datepicker 有一个 destroy 方法,但 Bootstrap 没有.它只有 .('remove')
方法,但它不起作用.
Is there a way to destroy the Bootstrap datepicker dynamically updating its options like format, beforeShowDay, etc.?
I know that the jQuery UI datepicker has a destroy method but Bootstrap's has not. It only has the .('remove')
method but its not working.
我的目标是在更改输入时修改日期选择器的选项,例如:
My goal is to modify the options of the datepicker when changing an input, for example:
$('#employee').change( function() {
$('#date').datepicker('destroy'); //not working 'cause bootstrap hasnt a destroy method
$('#date').hide();
});
然后我在输入改变时调用初始化函数:
Then I call the initialize function when the input changes:
function updateCalendar(){
$('#date').datepicker({
format:"dd/mm/yyyy",
beforeShowDay: updateC //function that modifies the available days to show
});
}
推荐答案
$('.datepicker').datepicker('remove');
在删除它之前,请确保您的日期选择器对象在 DOM 中.在不删除的情况下,您可以隐藏日历并更改日期格式并进行更新.
Make sure you have your date picker object in DOM before removing it. Without removing you can hide the calendar and change the format of date and update it .
$('.datepicker').datepicker('update');
这篇关于动态重新初始化或销毁 Bootstrap 日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!