动态重新初始化或销毁Bootstrap日期选择器 [英] Re-initialize or destroy Bootstrap datepicker dynamically

查看:281
本文介绍了动态重新初始化或销毁Bootstrap日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以破坏Bootstrap日期选择器,从而动态更新其选项,例如format,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆