如果日期大于,我在表td上设置css类的脚本有问题。脚本只能在今天使用。如果td中的日期小于星期且大于星期,则ifs的其余部分应设置类。
$('td:nth-child(7) ').each(function() {
var today = new Date();
var week = new Date();
var dd = today.getDate();
var ddd = today.getDate()+7;
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = dd + '/' + mm + '/' + yyyy;
if ($(this).text() == today) {
$(this).closest("td").addClass("red");
}
if ($(this).text() < today + 7 && $(this).text() != today ) {
$(this).closest("td").addClass("yellow");
}
if ($(this).text() > today + 7) {
$(this).closest("td").addClass("green");
}
});
最佳答案
尝试像
var displayedDate = new Date($(this).text());
var today = new Date();
if (displayedDate > today.setDate(today.getDate() + 7) {
// here displayed date is posterior to today + 7 days
}