首页 > 解决方案 > 如何在 JavaScript 完整日历中仅将自定义按钮用于月视图?

问题描述

我在我的 JavaScript 完整日历代码中添加了自定义按钮,但我只想显示这个按钮的月视图。

$(document).ready(function() {

  var calendar = $('#calendar').fullCalendar({

    editable: true,
    //FOR HEADER

    header: {
      left: ' prev,next today ',
      center: 'title',
      right: 'month,agendaDay,agendaWeek,myCustomButton'
    },
    customButtons: {
      myCustomButton: {
        text: 'REPEAT FOR NEXT MONTH',
        click: function() {
          alert('my custom button');
        }
      }
    }

  });

});

标签: javascriptajax

解决方案


如果您需要在月视图中为每一天附加按钮,那么您可以使用以下代码段:-

eventAfterAllRender: function(view) {

   if(view.name == 'month')
   {                       
       $('.fc-day').each(function(){
          $(this).append('<button>Day</button>');
       });      
    }
}       

推荐阅读