fullcalendar记住用户选项,例如.cookie中的月/周/日

Joh*_*lia 11 javascript jquery fullcalendar

我怎样才能修改fullcalendar插件,以便dayClick在cookie中保存不同的点击方法等?下次打开此日历时,如果默认为用户首选项.

已经使用cookie插件:https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js

在回答后更新工作cookie代码:

var calendarView = (!$.cookie('calendarDefaultView')) ? 'month' : $.cookie('calendarDefaultView');  
$calendar.fullCalendar({
    defaultView: calendarView,
    viewDisplay: function(view){
        $.cookie('calendarDefaultView', view.name, {expires:7, path: '/'});
    },
Run Code Online (Sandbox Code Playgroud)

Kai*_*mer 11

您需要的两个fullcalendar方法是:

//pull viewName from the cookie or set as default
var viewName='month'; //or basicWeek, basicDay, agendaWeek, agendaDay
$("#fullcalendar").fullCalendar( 'changeView', viewName );
Run Code Online (Sandbox Code Playgroud)

$('#fullcalendar').fullCalendar({
        viewDisplay: function( view )
        {
           //save your cookie here, it's triggered each time the view changes
        }
});
Run Code Online (Sandbox Code Playgroud)

这应该会让你走上正确的道路.我没有看到保存饼干b/c我认为你有控制权.

  • 干净的解决方案!很高兴我能帮助你. (2认同)