在我的 fullcalendar v4.3.1 应用程序中,我想向事件添加一些具有 javascript 功能的按钮 我做决定的例子:
window.calendarEventsObject = new FullCalendar.Calendar(calendarEl, {
plugins: ['dayGrid'],
eventRender: function (eventInfo) {
eventInfo.el.querySelector('.fc-title').append("<i class='fa fa-external-link pull-right'>7890</i>");
// I see text in title , but not html element, as I expected
// eventInfo.el.querySelector('.fc-title').html("<i class='fa fa-external-link pull-right'>7890</i>");
// If to uncomment the lline above I got error eventInfo.el.querySelector(...).html is not a function
},
events: eventsList,
showNonCurrentDates: false,
editable: true,
allDaySlot: true,
selectable: true,
selectHelper: true,
selectOverlap: false,
fixedWeekCount: false,
aspectRatio: 0.4,
height: 700,
});
哪种方式有效?
谢谢!
最佳答案
出现“.html 不是函数”错误是因为 .html 是 jquery function并且 el
不是 jQuery 对象(从 fullCalendar 4 开始)。
而 .append()
仅附加纯文本,而不附加 HTML。这是 mentioned in the documentation
如果你想附加一个 HTML 字符串,那么最简单的方法是使用 innerHTML
:
eventRender: function (eventInfo) {
eventInfo.el.querySelector('.fc-title').innerHTML += "<i class='fa fa-external-link pull-right'>7890</i>";
}
关于javascript - 在 fullcalendar v4 事件中添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57656685/