Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何选择tbody内具有特定背景色的所有tr_Jquery_Css_Html - Fatal编程技术网

Jquery 如何选择tbody内具有特定背景色的所有tr

Jquery 如何选择tbody内具有特定背景色的所有tr,jquery,css,html,Jquery,Css,Html,我有一张桌子,上面有一个特殊的背景色 <table> <tbody id="tbodyProjectList"> <tr> <th>Name</th> <th>Status</th> </tr> <tr> <td>wildlife</td> <td>archived</td> </tr> <tr style="backgr

我有一张桌子,上面有一个特殊的背景色

<table>
<tbody id="tbodyProjectList">
<tr>
<th>Name</th>
<th>Status</th> 
</tr>
<tr>
<td>wildlife</td>
<td>archived</td>
</tr>
<tr style="background-color:#4F4F4F">
<td>Xperia Z</td>
<td>archived</td>
</tr>
<tr>
<td>Manchester</td>
<td>Running</td>
</tr>
<tr>
<tr style="background-color:#4F4F4F">
<td>Restored</td>
</tr>
</tbody>
</table>
我也这么做了

$("#tbodyProjectList").find("tr background-color:#404040");
但不起作用。对象为空。当我在firebug中执行此操作时,它返回对象[]

可能是这样

$('#tbodyProjectList tr[style*=background-color:#404040]');

如果使用的是“属性等于选择器”,则选择器应为:

$("#tbodyProjectList").find("tr[style='background-color:#404040']");
但是如果向元素添加其他样式,选择器很容易失败,最好使用.filter方法:


请注意,您可以使用类来过滤元素,基于CSS属性选择元素是个坏主意。

您可以使用此代码查找具有特定背景颜色的tr

<table>
<tbody id="tbodyProjectList">
<tr>
<th>Name</th>
<th>Status</th> 
</tr>
<tr>
<td>wildlife</td>
<td>archived</td>
</tr>
<tr style="background-color:#4F4F4F">
<td>Xperia Z</td>
<td>archived</td>
</tr>
<tr>
<td>Manchester</td>
<td>Running</td>
</tr>
<tr>
<tr style="background-color:#4F4F4F">
<td>Restored</td>
</tr>
</tbody>
</table>

$'tr'.filterfunction{if$this.css'background-color'==4F4F4Freturn$this;}

,因为它不是属性或元素选择器。你为什么不使用类?@epascarello-你实际上可以使用属性选择器来实现这一点,但这似乎是一个非常糟糕的主意,是我见过的最糟糕的主意之一,如果在样式中还有其他东西的话?我知道这个例子没有那么好的选择。css‘background-color’他建议所有浏览器都支持rgb吗?不,大多数现代浏览器都支持rgb。我从第二个代码块中得到了答案,去掉了一个“=”符号
$("#tbodyProjectList tr").filter(function() {
    return $(this).css('background-color') === 'rgb(79, 79, 79)'; 
});