fullMalendar在nextMonth视图

时间:2016-06-23 11:11:46

标签: javascript jquery html events fullcalendar

$(document).ready(function() {
var date = new Date();

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title'
        //right: 'month,basicWeek,basicDay'
    },

    defaultDate: new Date(),
    editable: true,
    events: [],
    firstDay: 6,
    //eventLimit: true, // allow "more" link when too many events
    dayClick: function (date,allDay,jsEvent,view) {

        var findByClass = $('.week-highlight');
        if (findByClass.length < 1) {

            $(this).parent().addClass('week-highlight');

            var e = $('<div></div>'); //element
            var cal = $('#calendarContainer').append(e);
            e.attr('id','myCalendar');

            //Open second Calendar if week selected on 1st calendar
            $('#myCalendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title'
                    //right: 'month,basicWeek,basicDay'
                },
                defaultDate: new Date(),
                editable: false,
                //events: [],
                firstDay: 6,
                events: function () {
                    var fetchDate; 

                    var clickedDate = $('#calendar').on('click','.fc-day,.fc-day-number',function(e){
                        e.stopPropagation();  
                        fetchDate = $(this).data("date");
                        var thisDate = $('#myCalendar').find(".fc-day[data-date='"+fetchDate+"']");

                        //add id for each td on $(#myCalenda), then thisDate parent parent ...
                        thisDate.addClass('disabled');
                        thisDate.parent().addClass('disabled');

                        console.log(fetchDate);
                        console.log(thisDate);
                    });
                    //fetchDate is undefined here must move to clickedDate...
                },
                //fallBack to previous calendar
                dayClick: function (date,allDay,jsEvent,view) {
                    var findByClass = $('.week-highlight1');

                    // is this the GODDAMN DISABLED WEEK?!?!!!!!11o1111o
                    if ($(this).closest("tr").hasClass("disabled")) {
                        return;
                    }

                    if (findByClass.length < 1) {
                        $(this).parent().addClass('week-highlight1');
                    }
                    else {
                        findByClass.attr('class','');
                    }
                }
            });
        }
        else {
            findByClass.attr('class',' ');
            $('#myCalendar').detach();
        }
    }
});

});

我的HTML就是这样 <div id='calendar'></div> <div id="calendarContainer"> </div>

我正在使用fullCalendar,我的问题是点击一个日期,它会突出显示&#39;整整一周,指向那一天,但是当我点击查看下个月,然后我回到那个突出显示的月份。一周(日历重置清除所有添加的类)。无论如何要保存那一行的状态?!或者可能将其添加到活动中? 我不知道自己是否清楚但是thnkz。

1 个答案:

答案 0 :(得分:0)

您应该将相同的代码添加到viewRender中,而不仅仅是dayClick,这样当您切换视图时,您的突出显示状态就会保持不变。