Bootstrap Datepicker重新初始化日期格式 [英] Bootstrap Datepicker re-initialize date format

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

问题描述

我有一个默认格式为 mm / dd / yyyy 的Bootstrap datepicker,我已经选择了可以将
格式从mm / dd / yyyy 更改为 dd / mm / yyyy 并反向。



在选择更改时,我想要我的datepicker更改格式。



我尝试过

  find('#options-date_format' .on('change',function(){
$(#picker)。datepicker({format:formatDate})
});

但它不工作,我找不到这样做的方法。
还尝试删除/摧毁datepicker但是我有javascript错误。



谢谢

解决方案

确定我解决这个扩展的bootstra-datepicker.js

  setFormat:function(format){
this.format = DPGlobal.parseFormat(format);
}

并调用该函数



on('change',function(){
$(#picker)。datepicker('setFormat') newFormat);
});


I have Bootstrap datepicker with default format mm/dd/yyyy, and I have select where I can change format from mm/dd/yyyy to dd/mm/yyyy and reverse.

On select change I want to my datepicker change format.

I tried

find('#options-date_format').on('change', function(){
    $("#picker").datepicker({format: formatDate})
});

but It's not working, and I can't find way of doing this. Also tried to remove / destroy datepicker but I got javascript error.

Thanks

解决方案

Ok I resolve this extending bootstra-datepicker.js

setFormat: function(format) {
    this.format = DPGlobal.parseFormat(format);
}

And call that function

find('#options-date_format').on('change', function(){
    $("#picker").datepicker('setFormat', newFormat);
});

这篇关于Bootstrap Datepicker重新初始化日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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