如何禁用已预订的日期?
how to disable already booked dates?
我有一个用于预订酒店房间的表格,其中有两个字段,分别称为入住和退房。我在这里使用 jQuery 日期选择器来预订房间 我不想显示那些已经预订的日期。我试过这样。
$(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);
}
});
});
这个fiddle应该对你有帮助,你只需要找出你想要禁用的日期数组
var array = ["2015-06-14","2015-06-15","2015-06-16"]
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ array.indexOf(string) == -1 ]
}
});
http://jsfiddle.net/CxNNh/2201/
这是更新后的 jsfiddle 适合我
我有一个用于预订酒店房间的表格,其中有两个字段,分别称为入住和退房。我在这里使用 jQuery 日期选择器来预订房间 我不想显示那些已经预订的日期。我试过这样。
$(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);
}
});
});
这个fiddle应该对你有帮助,你只需要找出你想要禁用的日期数组
var array = ["2015-06-14","2015-06-15","2015-06-16"]
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ array.indexOf(string) == -1 ]
}
});
http://jsfiddle.net/CxNNh/2201/
这是更新后的 jsfiddle 适合我