4

我正在为日历使用 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')

4

1 回答 1

3

在单元格中添加一个类

 $('#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;
            }
        }
});

并通过日历表中的以下方法检查该类

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

      if($(this).hasClass('absent'))
      {
       $(this).attr('title','Absent');
      }
     });
   });
于 2019-12-13T10:34:20.953 回答