我目前正在使用此代码向表中的每隔一行添加一个类。
$(".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 中,也可能在其他中)。
关于jquery - 使用 jquery 选择每隔 2 个表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2782088/