微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用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,可能是其他人).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐