Bootstrap DateTimePicker增加1天的时间 [英] Bootstrap datetimepicker add 1 day to mindate
本文介绍了Bootstrap DateTimePicker增加1天的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用引导程序datetimepicker,如何在datetimepicker引导程序minDate
中添加一天?
I'm using bootstrap datetimepicker, how do I add one day in datetimepicker bootstrap minDate
?
我想过滤minDate
1天以上.例如,我的checkIn
datetimepicker是02/16/18,那么在checkOut
datetimepicker中禁用了02/16/18的日期.
I want to filter the minDate
for more 1 day. For example my checkIn
datetimepicker is 02/16/18 then the the date to 02/16/18 is disabled in checkOut
datetimepicker.
<script>
$(function () {
$('#CheckIn').datetimepicker({
format: 'MM/DD/YYYY'
});
$('#CheckOut').datetimepicker({
useCurrent: false,//Important! See issue #1075
format: 'MM/DD/YYYY'
});
$("#CheckIn").on("dp.change", function (e) {
$('#CheckOut').data("DateTimePicker").minDate(e.date);
});
$("#CheckOut").on("dp.change", function (e) {
$('#CheckIn').data("DateTimePicker").maxDate(e.date);
});
});
</script>
推荐答案
As the docs says, dp.change
:
更改日期时触发.
Fired when the date is changed.
参数:
e = {
date, //date the picker changed to. Type: moment object (clone)
oldDate //previous date. Type: moment object (clone) or false in the event of a null
}
由于e.date
是矩对象,因此可以使用 add
方法
since e.date
is a moment object you can use add
method.
这里有个例子:
$(function () {
$('#CheckIn').datetimepicker({
format: 'MM/DD/YYYY'
});
$('#CheckOut').datetimepicker({
useCurrent: false,//Important! See issue #1075
format: 'MM/DD/YYYY'
});
$("#CheckIn").on("dp.change", function (e) {
if( e.date ){
e.date.add(1, 'day');
}
$('#CheckOut').data("DateTimePicker").minDate(e.date);
});
$("#CheckOut").on("dp.change", function (e) {
$('#CheckIn').data("DateTimePicker").maxDate(e.date);
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.4/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id="CheckIn">
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id="CheckOut">
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
这篇关于Bootstrap DateTimePicker增加1天的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文