如何将事件绑定到fullcalendar中的时间段?

时间:2015-01-11 01:37:26

标签: javascript fullcalendar

我希望绑定到时间段上的双击事件,以便显示警报。这是我目前使用的代码

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    defaultDate: '2014-11-12',
    editable: true,
    eventLimit: true, 
    events: [
        {
        title: 'All Day Event',
        start: '2014-11-01'
        }
    ],
    eventRender: function(event, element) {
        element.bind('dblclick', function() {
            alert("dblclick event");
        });
    }
});

它使用eventRender选项绑定事件的双击事件,这是有效的。但我想绑定到时间段上的双击事件以显示上面的警报。我怎么能这样做呢?

1 个答案:

答案 0 :(得分:0)

我发现使用dayClick选项可以解决此问题:

    var delay = 300, clicks = 0, timer = null;

    dayClick: function (date, allDay, jsEvent, view) {

             clicks++;  //count clicks

                 if(clicks === 1) {

                       timer = setTimeout(function() {

                       alert('Single Click'); //perform single-click action

                       clicks = 0;  //after action performed, reset counter

                             }, delay);

                  } else {

                         clearTimeout(timer);  //prevent single-click action

                         alert('Double Click');  //perform double-click action

                         clicks = 0;  //after action performed, reset counter

                         }
                  }