Osc*_*lal 1 javascript jquery row html-table
我试图用jQuery选择除了第一个(列标题)之外的表中的所有行,为此我有这个选择器:
$("#tableID tr:not(:first)")
Run Code Online (Sandbox Code Playgroud)
有三行,一列用于列标题,两列用于内容,选择器返回4,但如果我这样做:
$("#tableID tr")
Run Code Online (Sandbox Code Playgroud)
它返回三行就好了.我在选择器中遗漏了什么吗?
如果它有帮助我做了截图:

给我问题的代码就是这个(这很简单,我不明白它为什么不起作用)
function addTableColumn() {
var uls = $('#debate ul').length;
$('#debate tr:first ').append("<th id='foo'>foo title</th>");
$("#debate tr:not(#debate tr:first)").append("<td><ul id='sortable" + (uls+1) + "' class='connectedSortable'></ul></td>").hide().fadeIn("slow");
alert("I'm seeing " + $('#debate tr:not(:first)').length + " rows (without first row), type: " + $('#debate tr:not(:first)')[0] + " but the row count returns (including titles) " + $('#debate tr').length);
makeSortable();
}
Run Code Online (Sandbox Code Playgroud)
如果它是标题行,我建议将标记更改为如下所示:
<table>
<thead>
<tr>
<th>Title</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
然后,在你的CSS/jQuery中,只选择<tr>s in <tbody>,它也更加语义化.