You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

定制版FullCalendar默认显示下月配置失效问题求助

如何让FullCalendar默认显示下一个月?

Hey John,我之前折腾FullCalendar的时候也碰到过类似的问题,直接改getMonth()加1没效果,大概率是没找对官方指定的配置项~ 下面给你两个靠谱的解决方案,适配不同版本的FullCalendar:

方案一:针对FullCalendar v5及以上版本(主流版本)

用官方提供的initialDate配置项,直接指定初始显示的日期为下一个月的第一天:

document.addEventListener('DOMContentLoaded', function() {
  const calendarEl = document.getElementById('calendar');
  
  // 计算下一个月的日期:自动处理跨年情况,比如12月的下一个月是次年1月
  const now = new Date();
  const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1);
  
  const calendar = new FullCalendar.Calendar(calendarEl, {
    initialDate: nextMonth, // 核心配置:让日历初始加载下一个月
    headerToolbar: {
      left: 'prev,next today',
      center: 'title',
      right: 'dayGridMonth,timeGridWeek,timeGridDay'
    },
    // 这里放你的其他定制配置...
  });

  calendar.render();
});

方案二:针对FullCalendar v4及更早版本

旧版本的配置项叫defaultDate,用法差不多:

$(document).ready(function() {
  const now = new Date();
  const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1);
  
  $('#calendar').fullCalendar({
    defaultDate: nextMonth, // 旧版本用这个配置
    // 你的其他配置项...
  });
});

为啥你之前的修改没效果?

你改的var m = date.getMonth()+1,大概率是修改了某个非核心逻辑的变量,并没有关联到FullCalendar初始化时的视图设置。FullCalendar有专门的配置项来控制初始显示的日期,直接用官方提供的方式才是正确的打开方式~

内容的提问来源于stack exchange,提问作者John DeFalco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:51:16