如何在选择第一个日期后禁用过去日期?
我已经尝试过此解决方案,但它不起作用:This is not working
我的代码:jsfiddle
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('.form-control-1').datepicker({
autoclose: true,
minViewMode: 1,
format: 'mm/yyyy'
}).on('changeDate', function (ev) {
if (ev.date.valueOf() > checkout.datepicker("getDate").valueOf() || !checkout.datepicker("getDate").valueOf()) {
var newDate = new Date(ev.date);
newDate.setDate(newDate.getDate() + 1);
checkout.datepicker("update", newDate);
}
$('.form-control-2')[0].focus();
});
var checkout = $('.form-control-2').datepicker({
beforeShowDay: function (date) {
if (!checkin.datepicker("getDate").valueOf()) {
return date.valueOf() >= new Date().valueOf();
} else {
return date.valueOf() > checkin.datepicker("getDate").valueOf();
}
},
autoclose: true,
minViewMode: 1,
format: 'mm/yyyy'
}).on('changeDate', function (ev) {});
答案 0 :(得分:0)
尝试并尝试后我终于得到了解决方案,所以我在这里分享,以防有人也需要这个:
<强> Working jsfiddle 强>
$( ".line" ).each(function(index, element) {
var startDate = new Date();
var fechaFin = new Date();
var FromEndDate = new Date();
var ToEndDate = new Date();
/* Find 'From' */
$(this).find(".form-control-1").addClass("from"+index);
/* Find 'To' */
$(this).find(".form-control-2").addClass("to"+index);
$(".from"+index).datepicker({
autoclose: true,
minViewMode: 1,
format: 'mm/yyyy'
}).on('changeDate', function(selected){
startDate = new Date(selected.date.valueOf());
startDate.setDate(startDate.getDate(new Date(selected.date.valueOf())));
$('.to'+index).datepicker('setStartDate', startDate);
});
$('.to'+index).datepicker({
autoclose: true,
minViewMode: 1,
format: 'mm/yyyy'
}).on('changeDate', function(selected){
FromEndDate = new Date(selected.date.valueOf());
FromEndDate.setDate(FromEndDate.getDate(new Date(selected.date.valueOf())));
$('.from'+index).datepicker('setEndDate', FromEndDate);
});
});