0

我发现了类似的主题,但我似乎无法让他们的解决方案适用于我的具体问题。我目前有一个日历,可以突出显示活动的开始日期。我需要更改它以突出显示开始日期到结束日期。注意:我没有编写此代码。似乎写这篇文章的人在这里留下了很多垃圾。请不要判断。

attachTocalendar : function(json, m, y) {
    var arr = new Array();
    if (json == undefined || !json.month || !json.year) {
        return;
    }
    m = json.month;
    y = json.year;

    if (json.events == null) {
        return;
    }
    if (json.total == 0) {
        return;
    }
    var edvs = {};
    var kds = new Array();
    var offset = en4.ynevent.getDateOffset(m, y);
    var tds = $$('.ynevent-cal-day');
    var selected = new Array(), numberOfEvent = new Array();
    for (var i = 0; i < json.total; ++i) {
        var evt = json.events[i];
        var s1 = evt.starttime.toTimestamp();
        var s0 = s1;
        var s2 = evt.endtime.toTimestamp();
        var ds = new Date(s1);
        var de = new Date(s2);
        var id = ds.getDateCellId();
        index = selected.indexOf(id);
        if (index < 0)
        {
            numberOfEvent[selected.length] = 1;
            selected.push(id);
        }
        else
        {
            numberOfEvent[index] = numberOfEvent[index] + 1;
        }
    }

    for (var i = 0; i < selected.length; i++) {
        var td = $(selected[i]);
        if (td != null) {
            if (!(td.hasClass("otherMonth"))){
                td.set('title', numberOfEvent[i] + ' ' + en4.core.language.translate(numberOfEvent[i] > 1 ? 'events' : 'event'));
                td.addClass('selected');
            }
        }
    }
},
4

1 回答 1

0

我建议您不要尝试全部选择它们,而是迭代它们。所以是这样的:

function highlightDates(startDate, endDate) {
    var curDate = startDate;
    var element;

    $('.selected').removeClass('selected'); // reset selection

    while (curDate <= endDate) {
        element = getElementForDate(curDate)
        element.addClass('selected');

        curDate.setDate(curDate.getDate() + 1); // add one day
    }
}

function getElementForDate(someDate) {
    return $('#day-' + someDate.getYear() + "-" + someDate.getMonth() + "-" + someDate.getDay());
}
于 2013-06-29T21:57:30.080 回答