本文介绍了Bootstrap 日期选择器中的多个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Boostrap-Datepicker 中选择多个日期.
我已经初始化了日期选择器,很好.
I have intialized the datepicker as such, just fine.
$('#datepicker2').datepicker();
现在我想在日历上选择多个日期:
$('#datepicker2').datepicker('setDate', [new Date(2014, 2, 5),new Date(2014, 3, 5)]);
它不起作用.未记录任何错误,但未选择日期.
It's not working. No errors are logged but the dates are not selected.
我使用的日期选择器版本在多日期方面存在一些问题,我使用了以前的版本并且它可以工作 - 可能是版本问题
the datepicker version I used had some issue with multidates, I used a previous version and it works - probably a version issue
不过这很好用:
$('#datepicker2').datepicker('setDate', new Date(2014, 2, 5));
推荐答案
有必要首先通过选项将您的日期选择器定义为多日期选择器.
It is necessary to first define your datepicker as a multidate picker through the options.
$('#datepicker2').datepicker({
multidate: true
});
然后你可以通过 setDates
方法设置你的日期:
Then you can set your dates via the setDates
method :
$('.date').datepicker({
multidate: true
});
$('.date').datepicker('setDates', [new Date(2014, 2, 5), new Date(2014, 3, 5)])
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
<input type="text" class="form-control date"/>
这篇关于Bootstrap 日期选择器中的多个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!