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
相关产品推荐
相关产品推荐

