FullCalendar dayClick not working (does nothing)

前端 未结 8 1818
天涯浪人
天涯浪人 2021-01-18 05:52

I am trying to get the \'dayClick\' function to work on FullCalendar, but when I press on any empty day, nothing happens. I have searched all over SO and cannot find any sol

8条回答
  •  猫巷女王i
    2021-01-18 06:33

    Ran into the same issue when using v4.2.0. Turns out that the interaction plugin wasn't loaded. The event is also now called dateClick instead of dayClick.

    A working example is below.

    document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');
    
        var calendar = new FullCalendar.Calendar(calendarEl, {
            height: 600,
            plugins: [ 'dayGrid', 'interaction' ],  // interaction plugin must be specified
            
            dateClick: function(info) {
                alert('Clicked on: ' + info.dateStr);
                alert('Current view: ' + info.view.type);
    
                // change the day's background color just for fun
                info.dayEl.style.backgroundColor = 'red';
            },
        });
    
        calendar.render();
      });
    
    
    
    
    
    
    
    
    

提交回复
热议问题