我目前正在使用以下 jQuery 脚本来突出显示表中的行,效果很好!
<script type="text/javascript">
$(document).ready(function()
{
$('table.grid tbody tr:odd').addClass('alt');
});
</script>
这对于每一行都是新记录的数据表非常有用,但是,我遇到了一个问题,我的记录占用了两行数据,并且想要修改 jQuery,使其呈现如下内容:
<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Record 1 Field 1</td>
<td>Record 1 Field 2</td>
</tr>
<tr>
<td colspan="2">Record 1 Field 3</td>
</tr>
<tr class="alt1">
<td>Record 2 Field 1</td>
<td>Record 2 Field 2</td>
</tr>
<tr class="alt2">
<td colspan="2">Record 2 Field 3</td>
</tr>
<tr>
<td>Record 3 Field 1</td>
<td>Record 3 Field 2</td>
</tr>
<tr>
<td colspan="3">Record 1 Field 3</td>
</tr>
<tr class="alt1">
<td>Record 4 Field 1</td>
<td>Record 4 Field 2</td>
</tr>
<tr class="alt2">
<td colspan="4">Record 2 Field 3</td>
</tr>
</tbody>
</table>
我将如何在 jQuery 中实现这一点,我希望每 3 行都有一个“alt1”类,每 4 行有一个“alt2”类?