How to alternate HTML table row colors using JSP?

后端 未结 6 1497
你的背包
你的背包 2020-12-05 17:35

How do I alternate HTML table row colors using JSP?

My CSS looks something like:

tr.odd {background-color: #EEDDEE}
tr.even {background-color: #EEEED         


        
6条回答
  •  温柔的废话
    2020-12-05 18:16

    Use the varStatus attribute on your forEach tag and JSTL will manage an instance of a javax.servlet.jsp.jstl.core.LoopTagStatus for you in the variable name you specify.

    You can then use a ternary operator to easily output the appropriate class name:

    
      
        ...
      
    
    

    This JSTL primer from IBM has more information about the core tag library and what it gives you.

提交回复
热议问题