在 fullcalendar v4 事件中添加按钮

Add button in fullcalendar v4 event

在我的 fullcalendar v4.3.1 应用程序中,我想向事件添加一些带有 jsvascript 函数的按钮 我做决定的例子:

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 functionel 不是 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>";
}

演示:https://codepen.io/ADyson82/pen/JjPJXeb