Fullcalendar jquery plugin Show years on nextYear buttons

落花浮王杯 提交于 2019-12-12 05:57:36

问题


I'm using the fullcalendar jquery plugin, and would like to display 2009 and 2011 in the nextYear and prevYear buttons.

For exmaple:

2009 May 2010 2011

I know I can put static text on the buttons like this:

buttonText: { prevYear: '2009', nextYear: '2011' },

But I would like those years to change, depending on the year that the calendar is currently viewing. There's documentation about 'year' here: http://arshaw.com/fullcalendar/docs/current_date/ but I don't know how to get that 'year' property.

Any examples would be appreciated,

Thanks,

--Nate


回答1:


You would probably just want to overwrite the buttons yourself and add your own events

function setYearButtons()
{
    var currentDate = $("#mycal").fullCalendar( 'getDate' );

    // I'm not 100% sure on these class names, but you can inspect the dom and figure those out
    $(".fc-button-last span").text(currentDate.getYear() + 1); 
    $(".fc-button-first span").text(currentDate.getYear() - 1);
}

Which you could call each time the year changed.




回答2:


been meaning to get to this. currently not possible, but made an issue in the issue tracker: http://code.google.com/p/fullcalendar/issues/detail?id=488




回答3:


Similar to Joel's answer, but updated for FullCalendar v1.6.4:

var calendar = document.getElementById(...),
    $calendar = $(calendar ), // wrap calendar once
    prevYearButton,
    nextYearButton;

$calendar.fullCalendar({
    ...
    viewRender: function () {
        var year = $calendar.fullCalendar('getDate').getFullYear();
        prevYearButton.innerHTML = year - 1;
        nextYearButton.innerHTML = year + 1;
    }
});

// do this after initializing FullCalendar
prevYearButton = calendar.querySelector('.fc-button-prevYear');
nextYearButton = calendar.querySelector('.fc-button-nextYear');


来源:https://stackoverflow.com/questions/2835953/fullcalendar-jquery-plugin-show-years-on-nextyear-buttons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!