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

FullCalendar dayClick事件无法获取点击日期问题求助

解决FullCalendar获取点击日期的问题

Hey there! I see exactly what's going on here. Your current code uses $('#calendar').fullCalendar('getDate'), which pulls the current view date of the calendar, not the specific day you clicked on. Let's fix this to get the clicked date directly:

关键要点

  • FullCalendar的dayClick回调函数本身就会把点击的日期对象作为第一个参数传递给函数,你完全不需要额外调用getDate()来获取。
  • 你代码里最后一行还有个小bug:'dat'是字符串字面量,应该直接用变量dat,否则日历会尝试跳转到一个无效的日期。

修改后的代码

dayClick: function(date) { 
  // 直接使用回调传入的date参数,就是点击的日期
  var dat = $.fullCalendar.formatDate(date, "YYYY-MM-DD"); 
  alert("The date is " + dat); 
  // 注意这里去掉dat的引号,用变量本身
  $('#calendar1').fullCalendar('changeView', 'agendaDay', dat); 
}

这样修改后,每次点击日历上的任意日期,都会弹出对应的日期,并且日历视图会跳转到你点击的那天的日程视图啦。

内容的提问来源于stack exchange,提问作者abhi lad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:36:08