【问题标题】:Alternating colors in table in jsp using CSS [duplicate]使用CSS在jsp中的表格中交替颜色[重复]
【发布时间】:2011-05-02 12:10:42
【问题描述】:

可能的重复:
How to alternate HTML table row colors using JSP?
Table row - Giving alternate colors

谁能提供在jsp文件中使用CSS在表格中动态添加行的基本代码,请提供此代码?

【问题讨论】:

标签: html css jsp dynamic html-table


【解决方案1】:
<table>
<?
    boolean evenRow = true;
    for (int i = 0; i < numRowsToDisplay; i++)
    {
?>

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

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

【讨论】:

  • 感谢莱利的支持。
【解决方案2】:

基本上有两种选择:

  • 要么您必须为 jsp 中的所有偶数(或奇数)行添加样式类
  • 或者您可以使用 javascript 在客户端动态执行此操作(如果可以选择)

【讨论】:

    【解决方案3】:

    【讨论】:

    • 浏览器支持吗?特别是 IE?
    • 它是正式的 CSS 3 我相信不是在 IE9 之前,替代方法是查看 jQuery.com,因为它包含一个支持这些结构并允许您创建交替效果的 CSS 选择器寻找。
    • 回答我自己的问题:不,他们没有。 quirksmode.org/css/contents.html#t38
    • @seanizer - 是的,但是嘿,IE 可能不是 OP 的考虑因素。
    【解决方案4】:

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

    【讨论】:

    猜你喜欢
    • 2016-07-08
    • 2010-09-19
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多