2013-06-25 18 views
4

我在我的應用程序中使用了數據表jQuery。當我使用數據表jQuery爲我的行設置替代顏色時,我遇到了一個問題。也就是說,在表格中,第2,3,4,第5,第6行全部以相同顏色顯示,之後交替顯示顏色。任何人都可以幫助我嗎?提前致謝。datatables jquery - 備用顏色的行

我在jquery.datatables.css代碼:

table.dataTable tr.odd { background-color: red; } 
table.dataTable tr.even { background-color: green; } 

我附加表的截圖。

enter image description here

當我檢查,每行有兩種類=「偶」或類=「奇」,但第2,第3,第4,第5,第6行上課=「奇偶」。我不知道爲什麼它是這樣的。

回答

5

找到了答案:

table.dataTable tr{ background-color: red; } 
table.dataTable tr:nth-child(even) { background-color: green; } 
2

嘗試:odd:even僞selecters

table.dataTable tr:odd { background-color: red; } 
table.dataTable tr:even { background-color: green;} 
+1

OP使用類,如'odd'和'even',我建議'CSS pseudos' –

+0

哦,是我不好,對不起,沒看到! +1 –

+0

嘗試...但不工作......謝謝 – kishore

1

在我的應用我已經使用

#tableid > thead >tr {background: #0F0} /* to color thead*/ 


table.dataTable tr.odd { background-color: red; } /* tr. not tr: */ 
table.dataTable tr.even { background-color: green;} 

的CSS規則和它的作品。希望爲您的應用程序的相同作品。

+0

我注意到了,DataTable添加了類「odd」或「even」與所有 – Snow

0

下面的代碼應該可以工作。 添加這些線路在數據表中的CSS文件

table.dataTable >tbody td { 
    text-align: center; 
    background: #99BCDB; 
} 

table.dataTable > tbody tr.odd td { 
    background: #EBF2F8 
; 
}