2016-03-15 67 views
0

我在應用程序中使用fullcalendar。我想通過單擊單元格來更改單元格背景顏色,但eventClick未被觸發。 任何人都可以幫助我。 這裏的代碼:fullCalendar eventClick沒有解僱

$(function() { 
 
      var date = new Date(); 
 
      var d = date.getDate(); 
 
      var m = date.getMonth(); 
 
      var y = date.getFullYear(); 
 

 

 
      $('#calendar').fullCalendar({ 
 
      
 
       eventClick: function (event) { 
 
        
 
        alert('hello'); 
 
        event.backgroundColor = 'yellow'; 
 
        $(this).css('background-color', 'red'); 
 

 
       }, 
 
       header: { 
 
        left: 'prev,next today', 
 
        center: 'title', 
 
        right: 'agendaWeek' 
 
       }, 
 
       editable: true, 
 
       defaultView: 'agendaWeek', 
 
       slotMinutes:60 
 
      }); 
 
     });

+0

您是否嘗試過[這](http://stackoverflow.com/questions/14657414/eventclick-change-background-color )和[這個](http://stackoverflow.com/questions/35797928/change-background-color-of-event-on-click-in-fullcalendar) – Bikee

回答

0

可以使用dayClick事件。

$(function() { 
      var date = new Date(); 
      var d = date.getDate(); 
      var m = date.getMonth(); 
      var y = date.getFullYear(); 


      $('#calendar').fullCalendar({ 

       dayClick: function (date, jsEvent) { //Added this, use jsEvent for more customization 
        $(jsEvent.target).css('background-color', 'red'); 
       }, 
       header: { 
        left: 'prev,next today', 
        center: 'title', 
        right: 'agendaWeek' 
       }, 
       editable: true, // Ensure you have this true 
       disableResizing:true, // Ensure you have this true 
       defaultView: 'agendaWeek', 
       slotMinutes:60 
      }); 
     }); 

在一天點擊你可以自定義你的CSS。

+0

dayClick爲我工作,但我需要改變顏色的小時,而不是整天 – natush

+0

@natush我已更新我的代碼,請檢查。這對我有用。 – SarangK

+0

現在,它是一個小時,但整個星期着色。這可能不可能。不管怎麼說,還是要謝謝你。 – natush