安東尼的回答並沒有爲我工作。首先,它不隱藏引導表類table-striped
,其次,對於錶行,沒有(或者至少看起來不是)內置類stripe
。
這裏是我的方法,我在表格中過濾了一個ID爲「reports」的行。
這裏有一個版本,如果你定義的類「條」爲<tr>
元素的使用方法:
// un-stripe table, since bootstrap striping doesn't work for filtered rows
$("table#reports").removeClass("table-striped");
// now add stripes to alternating rows
$rows.each(function (index) {
// but first remove class that may have been added by previous changes
$(this).removeClass("stripe");
if (index % 2 == 0) {
$(this).addClass("stripe");
}
});
如果你懶得來定義的CSS類「條紋」,那麼這裏有一個快速&髒版:
// un-stripe table, since bootstrap striping doesn't work for filtered rows
$("table#reports").removeClass("table-striped");
// now add stripes to alternating rows
$rows.each(function (index) {
// but first remove color that may have been added by previous changes:
$(this).css("background-color", "inherit");
if (index % 2 == 0) {
$(this).css("background-color", "#f9f9f9");
}
});
這個話題真的很不錯的文章,提供了一些解決方案:http://christianheilmann.com/2013/12/12/zebra-tables-using-nth-child-and-hidden-rows/ –