为Fullcalendar中的特定时段设置不同的颜色

Set different color to specific time slots in Fullcalendar

本文关键字:设置 颜色 段设置 Fullcalendar 定时      更新时间:2023-09-26

我正在使用Fullcalendar中的agendaDay视图。我有一个功能,当用户在特定的时间段、特定的日子点击时会阻止(它记录在数据库中)。我想知道我怎么能只为一天中的某些时段设置不同的颜色,特别是我屏蔽的线路。如何识别特定的时间线以更改其颜色?在我的上下文中,businessHours属性不是我所需要的,但几乎是这样的。

您必须在agendaDay视图中找到特定的行,然后更改它们的背景色。时间值在每个trspan中,因此我们需要首先找到它,然后如果行位于我们所需的时隙之间,则对其进行着色。

你可以通过使用这样的东西来实现:

$('tr').find('span').each( function(){
   var timeSlot = $(this).text();
   if(timeSlot> 13 && timeSlot < 18)    //Change 13 and 18 according to what you need
      $(this).closest('tr').css('background-color', '#000');
});