小智 16
您可以尝试在eventRender()方法中跳过事件:
eventRender: function(event, element, view)
{
if(event.start.getMonth() !== view.start.getMonth()) { return false; }
}
Run Code Online (Sandbox Code Playgroud)
小智 8
下个月和上个月的网格单元格具有"fc-other-month"类,因此您可以通过以下方式定位它们:
例如:隐藏日期编号,添加CSS:
.fc-other-month .fc-day-number { display:none;}
Run Code Online (Sandbox Code Playgroud)
或运行此JavaScript:
$(".fc-other-month .fc-day-number").hide()
Run Code Online (Sandbox Code Playgroud)
此答案中提供的解决方案都无法正确解决当前版本的 FullCalendar 的问题。以 Bascht 的答案为起点,我更新了他的方法以使用当前的 FullCalendar API。下面是完成此任务的工作示例代码:
eventRender: function (event, element) {
var eventDate = event.start;
var calendarDate = $('#activitiesCalendar').fullCalendar('getDate');
if (eventDate.get('month') !== calendarDate.get('month')) {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
添加此设置showNonCurrentDates: false。使用此设置,将不会显示不属于当月的日期和事件。
$('#calendarId').fullCalendar({
// Other settings
showNonCurrentDates: false
});
Run Code Online (Sandbox Code Playgroud)