jQuery FullCalendar通过jQuery Events获取事件ID

时间:2018-08-19 12:17:23

标签: javascript jquery html fullcalendar

我正在使用FullCalendar plugin来显示每日日历。 当用户单击事件时,我想获取日历事件ID。 我是通过FullCalendar点击事件来做到这一点的:

$('#calendar').fullCalendar({
    ...
    eventClick: function(calEvent, jsEvent, View)
    {
        console.log(calEvent.id);    
    }
});

我想通过使用JQuery事件获得相同的事件ID:

$('.fc-event').on('click', function(){
    console.log(...) //How do I get the the FullCalendar event id?
});

我非常灵活地执行此操作-使用JQuery从.fc-content获取ID或在事件本身中绑定一些ID,然后在需要时显示它。

非常感谢!

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法。 呈现日历事件时绑定ID:

$('#calendar').fullCalendar({
    ...
    eventRender: function(event, element)
    {
        element.find('.fc-content').attr("id", event.id);    
    }
});

然后您可以使用ID attr来使用JQuery事件

$('.fc-content').on('dblclick', function(){
    console.log($(this).attr("id"));
});