简体   繁体   中英

javascript FullCalendar eventClick not working

I want to add events and to set the eventClick

I tried to add event then set the eventClick but its not working

var calendar = $('#calendar');
calendar.fullCalendar('addEventSource', allEvents);


calendar.fullCalendar({
  eventClick: function() {
    alert(1);
  }
});

calendar.fullCalendar('refetchEvents');

i just noticed if i change the the ID calendar into myCalendar i dont have the calendar only buttons Today , < , > , and when i press TODAY its appear and the eventClick work

how to fix it?

$('#calendar').fullCalendar({
  eventClick: function(calEvent, jsEvent, view) {

    alert('Event: ' + calEvent.title);
    alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
    alert('View: ' + view.name);

    // change the border color just for fun
    $(this).css('border-color', 'red');

  }
});

As per the fullcalendar docs this will work for you.

You can set eventClick and other other attributes in options something like this:

var options = {
    defaultView: 'agendaWeek',
    header: {   
        right: 'today, prev, agendaWeek, month, next'
    },
    eventClick: function() {
        alert(2);
    }
};

then, set $('#calendar').fullCalendar(options) and add allEvents to calendar, according to FullCalendar documentation. Well, firstly you have to initialize the calendar and then adding events to the source, and by doing that you don't need to use refetchEvents again.

var calendar = $('#calendar').fullCalendar(options);
calendar.fullCalendar('addEventSource', allEvents);

Complete code can be seen here FullCalendar events and other options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM