使用jquery选择每隔2个表行

我目前正在使用此代码将类添加到表中的每个其他行.

$(".stripeMe tr:even").addClass("alt");

但是,在另一个表格中,我想在第3,4,7,8,11,12行等中添加一个类……

这可能吗?

解决方法

你需要这样做:

$(".stripeMe tr:nth-child(4n)").add(".stripeMe tr:nth-child(4n-1)").addClass("alt");​​​​​​​​
//or...
$("tr:nth-child(4n),tr:nth-child(4n-1)",".stripeMe").addClass("alt");​​​​​​​​​​​​​​​​​

You can see this working here.

使用这个:

$(".stripeMe tr:nth-child(4n),.stripeMe tr:nth-child(4n-1)").addClass("alt");​​​​​​​​

gets different results(即webkit,可能是其他人).

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...