jQuery datepicker多月模式重复周

时间:2012-03-28 12:51:11

标签: jquery datepicker

我希望在多月模式的其他月份修改jQuery datepicker而不是其他月份的重复日期(参见下图,我想删除红色标记的日期)。你能救我吗?

enter image description here

如你所知,这是我的日历代码:

$(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();
        }
    });
});

1 个答案:

答案 0 :(得分:1)

你应该摆脱这两行:

showOtherMonths: true,
selectOtherMonths: true,

选项showOtherMonths“在当月的开始或结束时显示其他月份的日期(不可选择)”和“selectOtherMonths”可选择当前月份之前或之后显示的其他月份的真实日期。“