Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 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 Answer

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);
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...