如何在数组中使用id =“tripDate”收集整个td的内部html,并使用JavaScript或jquery执行使用当前日期检查每个td值。
var currentDate = new Date();
var IDs = [];
$('.w3-table-all').find("td[id='tripDate']").each(function() {
IDs.push(this.id);
});
$.each(IDs, function(index, value) {
var actualDates = document.getElementById(value).innerHTML;
// didn't get all the values something went wrong ?????
if (actualDates < currentDate) {
//do something good
}
});
JWT token
答案 0 :(得分:1)
你迭代如下:
var now = new Date();
$(".w3-table-all td[id='tripDate']").each(function() {
var currentTripDateRange = this.innerText
, currentTripDates = currentTripDateRange.split(' - ')
, startDate =Date.parse(currentTripDates[0])
, lastDate =Date.parse(currentTripDates[1]);
if(now >= startDate && now <= lastDate){
//here is your selected dateRange
log(currentTripDateRange);
}
});
在此处找到有效的代码:http://jsbin.com/juqomonuci