如何在 daterangepicker 中的日期单元格上添加自定义标题

How to add Custom title on date cell in daterangepicker

我正在为日历使用 daterangepicker 库,并希望按日期显示从业者的状态 通过使用 isCustomDate 函数,我可以更新每个日期单元格

的 CSS
$('#calender').daterangepicker({
        singleDatePicker:true,
        minDate:moment(valid_from),
        maxDate:moment(valid_to),
        locale:{
            format:'DD MMM YYYY'
        },
        isCustomDate:function(date)
        {
            if(absent.indexOf(moment(date).format('YYYY-MM-DD'))>=0)
            {
                return 'bg-danger text-light';
            }
            else if(present.indexOf(moment(date).format('YYYY-MM-DD'))>=0)
            {
                return 'bg-primary text-light';
            }
        },
        isInvalidDate:function(date)
        {
           if(invalid.indexOf(moment(date).format('YYYY-MM-DD'))>=0)
           {
              return true;
            }
        }
});

但是如何为每个单元格添加标题如('Absent' OR 'Present')

在单元格

中添加 class
 $('#calender').daterangepicker({
        singleDatePicker:true,
        minDate:moment(valid_from),
        maxDate:moment(valid_to),
        locale:{
            format:'DD MMM YYYY'
        },
        isCustomDate:function(date)
        {
            if(absent.indexOf(moment(date).format('YYYY-MM-DD'))>=0)
            {
                return 'bg-danger text-light absent';
            }
            else if(present.indexOf(moment(date).format('YYYY-MM-DD'))>=0)
            {
                return 'bg-primary text-light';
            }
        },
        isInvalidDate:function(date)
        {
           if(invalid.indexOf(moment(date).format('YYYY-MM-DD'))>=0)
           {
              return true;
            }
        }
});

并通过以下方法在日历中检查 class table

   $('#calender').on('showCalendar.daterangepicker',function(){
    $('.calendar-table .table-condensed tbody td').each(function(i,e){

      if($(this).hasClass('absent'))
      {
       $(this).attr('title','Absent');
      }
     });
   });