选择当前日期后,bootstrap-datepicker清空字段 [英] bootstrap-datepicker empties field after selecting current date
本文介绍了选择当前日期后,bootstrap-datepicker清空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我启用了自动关闭,并且我从已选择的日历中选择了该字段,则会清空该字段,然后按预期关闭日期选择器。我怎么还有autoclose功能,但没有把它清空?
If I have autoclose enabled, and I select the field from the calendar that is already chosen, it empties the field and then closes the datepicker as expected. How can I still have the autoclose feature, but not have it empty the field?
- 确保autoclose已开启
- 选择日期。
- 再次打开日期选择器,再次选择当前选择的日期。
- 字段再次为空
- Make sure autoclose is on
- Select a date.
- open the datepicker again, select the currently selected date again.
- field is empty again
谢谢
推荐答案
Bootstrap Datepicker提供事件来实现目标。
Bootstrap Datepicker provides events that you can leverage to accomplish your goal.
这是一种方法:
$('#sandbox-container input').datepicker({
autoclose: true
});
$('#sandbox-container input').on('show', function(e){
if ( e.date ) {
$(this).data('stickyDate', e.date);
}
else {
$(this).data('stickyDate', null);
}
});
$('#sandbox-container input').on('hide', function(e){
var stickyDate = $(this).data('stickyDate');
if ( !e.date && stickyDate ) {
$(this).datepicker('setDate', stickyDate);
$(this).data('stickyDate', null);
}
});
不一定是最优雅的,但正如你在这里看到的,它可以解决问题:
Not necessarily the most elegant, but as you can see here, it does the trick:
http://jsfiddle.net/klenwell/LcqM7/(在Chrome中测试)
http://jsfiddle.net/klenwell/LcqM7/ (tested in Chrome)
这篇关于选择当前日期后,bootstrap-datepicker清空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文