我目前正在使用此代码将类添加到表中的每个其他行.
$(".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,可能是其他人).