簡體   English   中英

使用CSS樣式而不是jQuery

[英]Use css to style instead of jQuery

我遇到了以下代碼:

$("#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; 
}

jsFiddle示例

#TABLE_ID tr:nth-child(odd) {YOUR RULE HERE}
#customTable tr:nth-child(even) {background: #CCC}

#customTable tr:nth-child(odd) {background: #FFF}
 #customTable  tr:nth-child(even) {background: color;}
   #customTable tr:nth-child(odd) {background: color;}

此鏈接可能對您有幫助

http://www.w3.org/Style/Examples/007/evenodd.en.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM