6
我有一個預訂酒店房間的表格,我在這裏有兩個名爲checkIn和checkOut的字段。我在這裏使用jQuery datepicker預訂房間,我不想顯示那些已經預訂的日期。我嘗試過這樣。如何禁用已經預訂的日期?
$(function() {
var excludedCheckInDates = CHECKINDATES; // an array of already booked checkin dates
var excludedCheckOutDates = CHECKOUTDATES; // an array of already booked checkout dates
$.datepicker
.setDefaults({
defaultDate: '+1w',
changeMonth: true,
changeYear: true,
minDate: 0,
beforeShowDay: function(date) {
date = $.datepicker.formatDate('yy-mm-dd', date);
excludedCheckInDates = $.inArray(date,
excludedCheckInDates) < 0;
excludedCheckOutDates = $.inArray(date,
excludedCheckOutDates) < 0;
if (excludedCheckInDates) {
return [true, 'selectedDate'];
} else {
return false;
}
if (excludedCheckOutDates) {
return true;
} else {
return false;
}
return true;
}
});
$('#checkIn').datepicker({
onSelect: function(selectedDate) {
$('#checkIn').datepicker('option', 'minDate',
selectedDate || 0);
}
});
$('#checkOut').datepicker({
onSelect: function(selectedDate) {
$('#checkOut').datepicker('option', 'maxDate', selectedDate);
}
});
});
謝謝你的回答,我有約會的日期s格式'2015-06-25 00:00:00',我們如何使用datepicker格式化它? –
你正在使用日期選擇器,我不知道那裏是否有時間。你可以使用類似這樣的方式來修改日期格式'string.substring(10,「」)',它返回字符串的前10個字符 – VladNeacsu
我們如何排除除這些日期以外的所有日期?相反的方式..... – Mikeys4u