2015-11-05 63 views
0

我想添加一个像“.today-date”这样的类给fullCalendar中的weekView表头。 因为我想用背景色突出显示Today Date Header,就像突出显示td行一样。Fullcalendar将课程添加到weekView

周视图的单元格内容已经有一个类“.fc-today .fc-state-highlight”。

我尝试从fullcalendar的DayRender功能,但我的JavaScript的理解是有点低......我希望有人能帮助小白)

我的HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> 

<script src="http://momentjs.com/downloads/moment.js"></script> 

<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.3.1/fullcalendar.js"></script> 

<div id="calendar"></div> 

我JavaScript的

$(document).ready(function() { 
    $("#calendar").fullCalendar({ 
     defaultView: "basicWeek", 
    }); 
}); 

我的笔:codepen.io

回答

1

的DayRender将工作http://jsfiddle.net/6zq50vzc/3/

$('#calendar').fullCalendar({ 
    defaultView: 'basicWeek', 
    dayRender: function(date, cell) { 
     if (cell.hasClass('fc-today')) { // looking for today's cell 
      var index = cell.index(); // get the td offset 
      // find the corresponding item in header table 
      var header = $('#calendar thead.fc-head th').eq(index); 
      header.addClass('fc-today'); // update it with a class 
     } 
    } 
}); 
+0

很完美!非常非常感谢你! –

0
viewRender: function(view, element) { 
    if($('.fc-today').hasClass("fc-state-highlight")) { 
    $('.fc-head .fc-head-container th').eq($('.fc-today.fc-state-highlight').index()).addClass("today"); 
    } 
} 

这将需要突出显示的元素的索引,并使用该指数在日历的头添加一个今天类,其中显示的日期名。

+1

在发帖时解释你的答案*实际上做了什么总是很好,这种方式OP可以从中学习。 – Roberrrt

+1

感谢您的输入,但我不认为它需要解释,它会给出相同的输出作为接受的答案,一个不同的和更短的方法就是这样。无论如何,我正在编辑解释工作。 –