nth-child(n),n 可以是数字、关键词或公式。选择器匹配属于其父元素的第N个子元素,不论元素的类 型。
序号写法: 1. li:nth-child(3){background:orange;}
倍数写法: 1. li:nth-child(3n){background:orange;}
倍数分组匹配: 1. li:nth-child(3n+1){background:orange;}
2. li:nth-child(3n+5){background:orange;}
3. li:nth-child(5n-1){background:orange;}
隔三行设置颜色 1. $("tr:nth-child(3n)").css("background","#eee");
隔两行换一个颜色 1. $("tr:nth-child(2n)").css("background","#eee");
或者你是要每隔三行的第二行和第三行设置颜色?
1. $("tr:nth-child(3n)").css("background","#eee");
2. $("tr:nth-child(3n+2)").css("background","#ccc");