【发布时间】:2021-03-26 11:47:38
【问题描述】:
我正在尝试使用 jQuery 实现 FullCalendar
$(document).ready(function() {
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = $('#calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth'
});
calendar.render();
});
});
但日历没有显示在浏览器上
-关于FullCalendar的更多信息:[FullCalendar][1]- [1]:https://fullcalendar.io/
【问题讨论】:
-
您需要向 fullCalendar 构造函数提供 DOM 元素,而不是 jQuery 对象。它们不是同一件事。只需按照演示,很简单:fullcalendar.io/docs/initialize-globals。你不需要 jQuery。
-
好的.....但是我正在尝试使用 jQuery 来缓解问题,但它也无法正常工作,所以即使我使用他们使用它的方式我也无法使用jQuery的选择器
-
I'm trying to use jQuery to ease stuff out...当然,jQuery 有时对此很有用。但在这种情况下,它实际上并没有实现任何有用的东西。它只是给你带来了问题。even if I used the way they using it I'm not able to use the selectors of jQuery...在上面的代码中,您需要这些做什么?再次它没有用。附言“jQuery 的选择器”实际上是 CSS 选择器(除了一些额外的 jQuery 为边缘情况引入的选择器),因此如果您愿意,实际上可以使用与document.querySelector相同的选择器,而不是 document.getElementById -
您甚至不需要
initialView: 'dayGridMonth',因为这已经是默认设置了!这就是启动和运行基本日历所需的全部内容:codepen.io/ADyson82/pen/bGgEPPK - 我使用了 document.querySelector 而不是 document.getElementById,因此您可以使用与 jQuery 中相同的“选择器”。 -
呃,我肯定回答了这个问题。答案是“不要为此使用 jQuery,它没有用”。 fullCalendar 需要一个 DOM 元素,所以给它一个 DOM 元素。很简单。
标签: javascript jquery fullcalendar fullcalendar-5