看看这个:http: //jsfiddle.net/qbXVV/18/
HTML:
<button id="toggle">Toggle it!</button>
<table>
<tr class="sub"><td>Row 1</td></tr>
<tr class="tag"><td>Row 2</td></tr>
<tr class="sub"><td>Row 3</td></tr>
<tr class="tag"><td>Row 4</td></tr>
<tr class="sub"><td>Row 5</td></tr>
<tr class="tag"><td>Row 6</td></tr>
<tr class="sub"><td>Row 7</td></tr>
</table>
CSS:
tr:nth-of-type(even),.bg {
background-color: gray;
}
.hidden {
display:none;
}
JS:
$(document).ready(function () {
$('#toggle').click(function () {
$('.tag').toggleClass("hidden");
$(".sub:nth-child(4n+1)").toggleClass("bg");
});
});