如何在月视图中使日值可点击

Sky*_*ell 15 fullcalendar

有没有办法让月份视图中的月份值可以像谷歌日历一样点击?

我希望当用户点击一个月中的某一天(只是天数而不是整个块)时,fullCalendar会切换到该特定日期的日视图.

谢谢!

Mat*_*all 33

使用dayClick事件,changeView方法goToDate方法.

像这样的东西(未经测试):

$('#calendar').fullCalendar({
    dayClick: function(date, allDay, jsEvent, view) {

        if (allDay) {
            // Clicked on the entire day
            $('#calendar')
                .fullCalendar('changeView', 'agendaDay'/* or 'basicDay' */)
                .fullCalendar('gotoDate',
                    date.getFullYear(), date.getMonth(), date.getDate());
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

编辑重新:评论

您可以event.target在回调中查看:

$('#calendar').fullCalendar({
    dayClick: function(date, allDay, jsEvent, view) {

        if (allDay) {
            // Clicked on the entire day 

            if ($(jsEvent.target).is('div.fc-day-number')) {      
                // Clicked on the day number 

                $('#calendar') 
                    .fullCalendar('changeView', 'agendaDay'/* or 'basicDay' */) 
                    .fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate()); 
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

  • 如果用户点击日期块的任何地方而不是仅仅是日期编号,那么这不会切换视图吗? (4认同)
  • 太棒了......工作得很好.谢啦!我添加了一个css指令,'cursor:pointer'为'div.fc-day-number',所以当你将鼠标悬停在月份数上时,鼠标指针会变为小手. (3认同)
  • 奇怪的是,在最新版本中,如果你链接方法它们将无法工作,你必须解除它们的工作.您也可以简单地传递日期对象:$('#calendar').fullCalendar('changeView','basicDay'); $('#calendar').fullCalendar('gotoDate',date) (3认同)