我正在尝试选择某个类的表的偶数行。
所以表格如下:
Absolute row 1 -- virtual row 1 of class a Absolute row 2 -- virtual row 2 of class a (should be matched by css selector) Absolute row 3 -- virtual *row 1* of class b Absolute row 4 -- virtual row 3 of class a Absolute row 5 -- virtual row 4 of class a (should be matched by css selector)
我尝试使用此选择器:
.table-result tbody tr.include:nth-child(even) {background-color: #eeeeee;}
但是它仍然保持着不同类的想法
有解决方法吗?无需求助于表格中的表格?
HTML:
<table class="ui-widget ui-widget-content table-result" id="adspaceresult">
<thead>
<tr class="ui-widget-header">
<th>Type</th>
<th>Info</th>
<th>Average</th>
<th>Bid</th>
<th>Graph</th>
</tr>
</thead>
<tbody id="adrbody">
<tr class="include">
<td><button data-adtype="1" data-adspaceid="2" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
88x31</span></button></td>
<td></td>
<td>77</td>
<td>Bid</td>
<td>Graph</td>
</tr>
<tr>
<td colspan="5">Why hello there!</td>
</tr>
<tr class="include">
<td><button data-adtype="1" data-adspaceid="3" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
88x31</span></button></td>
<td></td>
<td>748102</td>
<td>Bid</td>
<td>Graph</td>
</tr>
<tr class="include">
<td><button data-adtype="1" data-adspaceid="5" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
88x31</span></button></td>
<td></td>
<td>226</td>
<td>Bid</td>
<td>Graph</td>
</tr>
<tr class="include">
<td><button data-adtype="1" data-adspaceid="6" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
88x31</span></button></td>
<td></td>
<td>6003</td>
<td>Bid</td>
<td>Graph</td>
</tr>
</tbody>
</table>
不应计入包含“为什么在那里打招呼”消息的tr。
答案 0 :(得分:0)
按类名选择行并选择备用元素
var list = $(".include")
for (i=0;i<list.length-1;i++)
{
if (i%2 == 0){
// do what you want
}
}
答案 1 :(得分:0)
如果行数有限,可以不这样做,但我不建议使用它
table .b, table .b~.b~.b, ... {background:white;}
table .b~.b, table .b~.b~.b~.b, ...{background:blue;}