我有一个预订酒店房间的表格,其中有两个字段,称为入住和退房。我在这里使用 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);
}
});
});
这个小提琴应该对你有帮助,你只需要找出你想要禁用的日期数组
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/ http://jsfiddle.net/CxNNh/2201/
这是适合我的更新后的 jsfiddle
http://jsfiddle.net/CxNNh/2202/ http://jsfiddle.net/CxNNh/2202/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)