Bootstrap datetimepicker 添加 1 天到 mindate
Bootstrap datetimepicker add 1 day to mindate
我正在使用 bootstrap datetimepicker,如何在 datetimepicker 中添加一天 bootstrap minDate
?
我想再过滤 minDate
1 天。例如,我的 checkIn
datetimepicker 是 02/16/18 那么 02/16/18 的日期在 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>
正如文档所说,dp.change
:
Fired when the date is changed.
Parameters:
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
方法。
这是一个活生生的例子:
$(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>
感谢您的大力帮助。它也适用于我。但我需要增加 3 天。如果有人需要我的代码,请使用它。
$(function (){
$('#datetimepicker1_1').datetimepicker({
minDate: new Date(),
date: new Date()
});
var endDate = new Date();
endDate.setDate(endDate.getDate()+4);
$('#datetimepicker2_1').datetimepicker({
minDate:endDate,
date: endDate
});
$("#datetimepicker1_1").on("dp.change", function (e){
if (e.date){
e.date.add(4,'day');
}
$('#datetimepicker2_1').data("DateTimePicker").minDate(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>
<input onkeyup="first_step_val()" maxlength="100" id='datetimepicker1_1' type="text" name="start_date" required="required" class="form-control" />
<input onkeyup="first_step_val()" maxlength="100" type="text" id='datetimepicker2_1' name="end_date" required="required" class="form-control" />
我正在使用 bootstrap datetimepicker,如何在 datetimepicker 中添加一天 bootstrap minDate
?
我想再过滤 minDate
1 天。例如,我的 checkIn
datetimepicker 是 02/16/18 那么 02/16/18 的日期在 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>
正如文档所说,dp.change
:
Fired when the date is changed.
Parameters:
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
方法。
这是一个活生生的例子:
$(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>
感谢您的大力帮助。它也适用于我。但我需要增加 3 天。如果有人需要我的代码,请使用它。
$(function (){
$('#datetimepicker1_1').datetimepicker({
minDate: new Date(),
date: new Date()
});
var endDate = new Date();
endDate.setDate(endDate.getDate()+4);
$('#datetimepicker2_1').datetimepicker({
minDate:endDate,
date: endDate
});
$("#datetimepicker1_1").on("dp.change", function (e){
if (e.date){
e.date.add(4,'day');
}
$('#datetimepicker2_1').data("DateTimePicker").minDate(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>
<input onkeyup="first_step_val()" maxlength="100" id='datetimepicker1_1' type="text" name="start_date" required="required" class="form-control" />
<input onkeyup="first_step_val()" maxlength="100" type="text" id='datetimepicker2_1' name="end_date" required="required" class="form-control" />