2010-10-29 66 views

回答

0

基本上有兩種選擇:

  • 要麼你有一個樣式類在JSP
  • 添加到所有偶數(或奇數)行,或者你可以動態地做到這一點與JavaScript客戶端(如果這是一個選項)
+0

感謝seanizer – 2010-10-30 09:48:50

0
+0

瀏覽器支持嗎? IE具體? – 2010-10-29 16:12:09

+0

它是官方的CSS 3我相信在IE9之前不是這樣,另一種方法是查看jQuery.com,因爲它包含一個支持這些構造的CSS選擇器,並允許您創建您正在尋找的交替效果。 – Lazarus 2010-10-29 16:14:18

+0

回答我自己的問題:不,他們沒有。 http://www.quirksmode.org/css/contents.html#t38 – 2010-10-29 16:14:32

1
<table> 
<? 
    boolean evenRow = true; 
    for (int i = 0; i < numRowsToDisplay; i++) 
    { 
?> 

<tr class="<?= evenRow? "evenrowstyle" : "oddrowstyle" ?>"><td>whatever</td></tr> 

<? 
     evenRow = !evenRow; 
    } 
?> 
</table> 
+0

感謝riley的支持。 – 2010-10-30 09:47:26

0

<style> 
#TableID tr:nt-child(odd){ 
background-color:white; 
} 

#TableID tr:nth-child(even){ 
background-color:silver; 
} 
</style> 
+0

在多個瀏覽器中失敗:http://www.quirksmode.org/css/contents.html#t38 – 2010-10-29 16:16:00

+0

感謝父親風暴 – 2010-10-30 09:48:03