首页 > 解决方案 > 如何在全日历上自定义过滤器

问题描述

有没有办法在完整日历上自定义过滤器?例如,我希望能够在不单击箭头键的情况下跳转到特定的月份或年份,使其更友好,而不像单击需要太多时间。如果有 - 我该如何定制它或需要什么代码?

例如:

当前月份是九月,我想去十二月

2019 年,但我想去 2020 年或更高

标签: javascriptphpcalendar

解决方案


您可以使用“gotoDate”功能

calendar.gotoDate('2020-12-1');

像这样 :

<button id="btn">go to dec 2020</button>

<script>
document.addEventListener('DOMContentLoaded', function() {

    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
        titleFormat: {year: 'numeric'},
        plugins: [ 'dayGrid', 'timeGrid', 'list', 'moment', 'momentTimezone'],
        header:{
            left: '',
            center: 'title',
            right: 'prevYear,nextYear'
        }   
    });

    calendar.render();

    // go to dec 2020
    $('#btn').click(function() {
        calendar.gotoDate('2020-12-1');
    });

});

考虑在 fullCalendar 插件之前初始化“时刻”库


推荐阅读