Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
524 views
in Technique[技术] by (71.8m points)

php - Fullcalendar, Make Today Button for current month active

Today button disable for current month. when you go next or previous month it appear as active(when click on the TODAY button control goes to current month).

In following code I am showing how to make today button active for current month.

 function makeTodaybtnActive()
      {
         $('#calendar button.fc-today-button').removeAttr('disabled');
         $('#calendar button.fc-today-button').removeClass('fc-state-disabled');
       }

(where #calendar is fullcalendar id)
call this function when calendar load

 $(window).load(function() {
    makeTodaybtnActive();
 });

Also in eventRender function

   $('#calendar').fullCalendar({
        eventRender: function(event, element) {
          makeTodaybtnActive();
        },
   });

When calendar load (page load) that time first code work and when change the month and goes to current month (by clicking today button) then second code make Today button active.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The 'today' button is made inactive automatically when today's date is visible in the rendered calendar area since there is no point in jumping to 'today' if it is already visible. If you really wish it to be always enabled it is possible https://jsfiddle.net/73b7rva6/

document.addEventListener('DOMContentLoaded', function() {
    $('#calendar').fullCalendar({
        eventAfterAllRender: function(view) { /* used this vs viewRender */
            makeTodayButtonActive();
        }
    });

    function makeTodayButtonActive() {
        /* turn off fc-state-disabled class and remove 'disabled' property */
        $('#calendar button.fc-today-button').removeClass('fc-state-disabled').prop('disabled', false);
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...