我遇到过这段代码:
$("#customTable tr:nth-child(odd)").addClass("newColour");
这会为表格的每个奇数行着色。
如何在 css 中处理而不是使用 jQuery 来执行它?
#customTable tr:nth-child(odd) {
background-color:#eee;
}
#customTable tr:nth-child(even) {
background-color:#fff;
}
#TABLE_ID tr:nth-child(odd) {YOUR RULE HERE}
#customTable tr:nth-child(even) {background: color;}
#customTable tr:nth-child(odd) {background: color;}
此链接可能对您有所帮助