How to call events on clicking prev and next button?

后端 未结 11 1538
天涯浪人
天涯浪人 2020-12-24 07:26

In jQuery fullcalendar we have previous and next buttons. How can we call some events on click of these buttons?

相关标签:
11条回答
  • 2020-12-24 08:18

    This worked for me:

    $('body').on('click', 'button.fc-prev-button', function() {
      //do something
    });
    
    $('body').on('click', 'button.fc-next-button', function() {
      //do something
    });
    
    0 讨论(0)
  • 2020-12-24 08:20

    When you click them, viewRender event is triggered. You could add your code inside it as well.

    $('#calendar').fullCalendar({
        viewRender: function(view, element) {
            //Do something
        }
    });
    
    0 讨论(0)
  • 2020-12-24 08:21

    Just a quick update, no idea for how long but the accepted answer works for me like this:

    $('.fc-prev-button').click(function(){
       alert('prev is clicked, do something');
    });
    
    $('.fc-next-button').click(function(){
       alert('nextis clicked, do something');
    });
    

    Notice slight change,

    also on today click is as follows:

    $(".fc-today-button").click(function () {
    

    Hope i helped someone.

    0 讨论(0)
  • 2020-12-24 08:22

    I see there are other working answers, but IMHO the simplest and more correct - at least using FullCalendar v.4 - is to intercept prev and next is to deal them in the same way of custom buttons.

    Here my setup (using toastr just for demo purposes)

    document.addEventListener('DOMContentLoaded', function() {
      var calendarEl = document.getElementById('calendar');
    
      var calendar = new FullCalendar.Calendar(calendarEl, {
        plugins: [ 'dayGrid', 'timeGrid' ],
        header: {
          left: 'dayGridMonth,timeGridWeek,timeGridDay',
          center: 'title',
          right: 'prev,next'
        },
        footer: {
          left: '',
          center: '',
          right: 'prev,next'
        },
        customButtons: {
          prev: {
            text: 'Prev',
            click: function() {
                        // so something before
                        toastr.warning("PREV button is going to be executed")
                        // do the original command
                        calendar.prev();
                        // do something after
                        toastr.warning("PREV button executed")
            }
          },
          next: {
            text: 'Next',
            click: function() {
                        // so something before
                        toastr.success("NEXT button is going to be executed")
                        // do the original command
                        calendar.next();
                        // do something after
                        toastr.success("NEXT button executed")
            }
          },
        }
      });
    
      calendar.render();
    });
    

    See a Codepen here

    0 讨论(0)
  • 2020-12-24 08:24

    Another solution is to define your custom prev/next button:

    $('#m_calendar').fullCalendar({
     header: {
             left: 'customPrevButton,customNextButton today',
             center: 'title',
     },
     customButtons: {
                    customPrevButton: {
                        text: 'custom prev !',
                        click: function () {
                            alert('custom prev ! clicked !');
    
                        }
                    },
                    customNextButton: {
                        text: 'custom ext!',
                        click: function () {
                           alert('custom ext ! clicked !');
                        }
                    },
                }
    });
    
    0 讨论(0)
提交回复
热议问题