我想出了這個功能,編號類添加到我的表表中的行內元素中添加編號,以TDS:JQuery的錶行
$('tr td:contains(".")').each(function(i){
$(this).addClass("reportcellno-" + i);
});
基本上在這裏,我正在尋找任何表單元格與小數點,我想通過他們interate通過他們每行內,並添加類reportcellno-1
,reportcellno-2
這工作相當好,我玩了一整天。唯一的問題是編號繼續,而不是按行進行限制。
從上面我的輸出HTML代碼:
<tr>
<td class="reportcellno-1">10.1</td>
<td class="reportcellno-2">5.7</td>
</tr>
<tr>
<td class="reportcellno-3">10.6</td>
<td class="reportcellno-4">10.9</td>
</tr>
而我其實想獲得這樣的:
<tr>
<td class="reportcellno-1">10.1</td>
<td class="reportcellno-2">5.7</td>
</tr>
<tr>
<td class="reportcellno-1">10.6</td>
<td class="reportcellno-2">10.9</td>
</tr>
所以基本上每個錶行,我要重新開始編號。我甚至不確定這是否可能。
'。兒童()'代替'.find()'進行更好。 –
@ŠimeVidas謝謝,編輯 –
完美,謝謝!我喜歡第一種方法。 –