1
我想修改jQuery datepicker在其他月的其他月份在多月模式下不重複的日子(見下圖,我想刪除紅色標記的日子)。你可以幫我嗎?jQuery datepicker多月模式重複周
至於你問,這是我的日曆代碼:
$(document).ready(function(){
var weeks = new Array();
function inWeeks(startDate) {
for (var i in weeks) {
if (weeks[i].getTime() == startDate.getTime()) return true;
}
return false;
}
function removeWeek(startDate) {
for (var i in weeks) {
if (weeks[i].getTime() == startDate.getTime()) {
weeks.splice(i, 1);
return;
}
}
}
function addWeek(startDate) {
weeks.push(startDate);
}
var selectCurrentWeek = function() {
window.setTimeout(function() {
$('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
}, 1);
}
$('.week-picker').datepicker({
numberOfMonths: 2,
showOtherMonths: true,
selectOtherMonths: true,
hideIfNoPrevNext: true,
firstDay: 1,
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
//var endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
if (inWeeks(startDate)) {
removeWeek(startDate);
} else {
addWeek(startDate);
}
selectCurrentWeek();
},
beforeShowDay: function(date) {
var cssClass = '';
for (var i in weeks) {
var startDate = weeks[i];
var endDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() - startDate.getDay() + 7);
if(date >= startDate && date <= endDate)
cssClass = 'ui-datepicker-selected-week-day';
}
return [true, cssClass];
},
onChangeMonthYear: function(year, month, inst) {
selectCurrentWeek();
}
});
});
您使用的是什麼日期選擇器?你的代碼是什麼樣的? – 2012-03-28 12:55:27
標準的jQuery datepicker(jquery-1.6.2,jquery-ui-1.8.14.custom) – 2012-03-28 12:58:44
正如@AndrewWhitaker所說,我們需要您發佈一段代碼。你想做的事情在jQuery的演示頁面上工作得很好...... http://jqueryui.com/demos/datepicker/#multiple-calendars – Jibou 2012-03-28 13:05:21