【发布时间】:2014-10-07 23:52:36
【问题描述】:
我有一张有很多行的表。有些行具有特殊的颜色,我想使用 jquery 获取该 tr 元素的数组。我使用了选择器,但没有用
$("#tbodySample").children("tr[background-color='rgb(79,79,79)']").length;
$("#tbodySample").children("tr[style='background-color:rgb(79,79,79)']").length;
$("#tbodySample").children("tr[style='{background-color:rgb(79,79,79)}']").length;
$("#tbodySample").children("tr[background-color='#4F4F4F']").length;
$("#tbodySample").children("tr[style='background-color:#4F4F4F']").length;
$("#tbodySample").children("tr[style='{background-color:#4F4F4F}']").length;
我的html是
<table>
<tbody id="tbodySample">
<tr class="selectable" style="background-color: rgb(79, 79, 79);">contents</tr>
<tr class="selectable" style="background-color: rgb(52, 52, 52);">contents</tr>
<tr class="selectable" style="background-color: rgb(52, 52, 52);">contents</tr>
<tr class="selectable" style="background-color: rgb(52, 52, 52);">contents</tr>
<tr class="selectable" style="background-color: rgb(79, 79, 79);">contents</tr>
.
.
.
</tbody>
</table>
以上所有语句都返回 0。 有没有可靠的方法来实现这一点?
【问题讨论】:
-
使用 css 类分配颜色,然后找到具有特定类的元素。让生活更轻松。
标签: jquery html jquery-selectors html-table