我正在使用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'或'Present')
在单元格中添加课程
$('#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');
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句