我有下表,我試圖找到一種方法來添加一個'高亮'類到單元格(class =「dateRow」)與最近的日期/時間。 在這種情況下,它將是第四個,其日期是'2013-05-30'。突出顯示錶格行中的最新日期
我已經嘗試了各種選擇,但似乎不能使它工作。有人可能會告訴我,因爲我一直在試圖弄清楚這一點,而且似乎無法使其發揮作用。
<table>
<tr class="topRow">
<td>Yes</td>
<td class="dateRow">2013-05-23 13:53:20</td>
<td class="dateRow">2013-05-21 13:53:21</td>
<td class="dateRow">2013-05-29 13:53:22</td>
<td class="dateRow">2013-05-30 13:53:23</td>
<td class="dateRow">2013-05-29 13:53:24</td>
<td class="dateRow">2013-05-28 13:53:19</td>
<td>Some Text</td>
<td class="dateRow">2013-05-27 13:53:18</td>
</tr>
</table>
我試着去適應最新的JS如下:
<script>
$(window).load(function()
{
$('.thisRow').each(function() {
var $tds = $(this).children('td'),
max = null,
maxIndex = null;
$tds.each(function() {
var value = +$(this).text().substr(1);
if(isNaN(value)) {
if(!max || value > max) {
max = value;
maxIndex = $(this).index();
}
}
});
if(maxIndex !== null) {
$tds.eq(maxIndex).addClass('highlight');
}
});
}
);
</script>
我想,這是一個必須適應NaN的,因爲這並至少選中一個單元格,雖然最後一。
'我曾嘗試過各種options'哪些選項是那些?向我們展示一些代碼! –
對不起,我曾嘗試過各種各樣的事情,其中大部分都失敗了。我已經添加了最近的一個,這部分工作(它至少突出了cel)。我認爲這是NaN需要改變的東西,但看不到什麼? – IGGt