问题
How to select rows in a html table except the table header rows using jquery?
<table id="mytable">
<thead>
<tr>
<th>
Foo
</th>
<td>
Lorem
</td>
<td>
Ipsum
</td>
</tr>
</thead>
<tr>
<th>
Bar
</th>
<td>
Dolor
</td>
<td>
Sit
</td>
</tr>
<tr>
<th>
Baz
</th>
<td>
Amet
</td>
<td>
Consectetuer
</td>
</tr>
</table>
回答1:
$('tr').not('thead tr').addClass('selected')
回答2:
You should wrap the rows in a <tbody>
element (some browsers will do this anyway!), then select the children of that tbody:
$('#mytable > tbody > tr');
回答3:
You can exclude thead
using not
$('#mytable tr').not('thead tr')
回答4:
This selector selects all tr elements in #mytable except the first one (the header).
$('#mytable tr:not(:first)')
来源:https://stackoverflow.com/questions/3350924/select-rows-in-a-table-except-the-table-header-rows