我正在使用日期选择器来选择酒店日期。我需要日期选择器来不允许用户在两个日历中选择同一天,这里是一个jsfiddle
它应该是这样工作的: - 你不能添加一个低于“从”日期的“到”日期 - 你不能为“到”和“从”日期选择同一天
这是我的代码:
$( "#booking-from" ).datepicker({
defaultDate: "+1w",
minDate: 0,
firstDay: 0,
dateFormat: 'dd-mm-yy',
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
//$( "#booking-to" ).datepicker( "option", "minDate", selectedDate );
/*var day1 = $("#booking-from").datepicker('getDate').getDate() + 1;
var month1 = $("#booking-from").datepicker('getDate').getMonth();
var year1 = $("#booking-from").datepicker('getDate').getFullYear();
year1 = year1.toString().substr(2,2);
var fullDate = day1 + "-" + month1 + "-" + year1;*/
$( "#booking-to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#booking-to" ).datepicker({
defaultDate: "+1w",
minDate: '+2d',
changeMonth: true,
firstDay: 0,
dateFormat: 'dd-mm-yy',
numberOfMonths: 1,
onClose: function( selectedDate ) {
//$( "#booking-from" ).datepicker( "option", "maxDate", $('#booking-to').datepicker('getDate') );
},
onSelect: function (){
calculateBooking();
}
});
$("#booking-from").datepicker('setDate', '+1');
$("#booking-to").datepicker('setDate', '+8');
我该怎么做?