我需要计算表中的日期是否在 5 天内并更新父行的类。我能够做到这一点(在 FF 和 Chrome 中),但由于某种原因,它在 IE8 中不起作用。
表中的项目将具有类似“08/28/13”的日期,而 TD 将具有“时间”类。
$('td:contains("Scheduled")').parents('tr').addClass('scheduled');
$("td.time").each(function (index) {
var date = $(this).text();
//sep date
var year = date.substring(6, 10);
var month = date.substring(0, 2);
var day = date.substring(3, 5);
alert(month + ' ' + day + ', ' + year);
//today
var d = new Date();
var today = d.getDate();
var m = new Array();
m[0] = "01";
m[1] = "02";
m[2] = "03";
m[3] = "04";
m[4] = "05";
m[5] = "06";
m[6] = "07";
m[7] = "08";
m[8] = "09";
m[9] = "10";
m[10] = "11";
m[11] = "12";
var b = d.getMonth();
var n = parseInt(m[d.getMonth()]);
var monthStart = new Date(year, b, 1);
var monthEnd = new Date(year, b + 1, 1);
var monthLength = (monthEnd - monthStart) / (1000 * 60 * 60 * 24);
var nextMonth = n + 1;
var dayDiff = 5 - (monthLength - today);
if ((monthLength - 5) < today && nextMonth == month && day < dayDiff) {
if (!$(this).parents('tr').hasClass('scheduled')) {
$(this).parents('tr').addClass('urgent');
};
};
if (n == month && today < day && day <= (today + 5)) {
if (!$(this).parents('tr').hasClass('scheduled')) {
$(this).parents('tr').addClass('urgent');
};
};
});