How do I alternate HTML table row colors using JSP?
My CSS looks something like:
tr.odd {background-color: #EEDDEE}
tr.even {background-color: #EEEEDD}
I want to use <c:forEach>
to iterate over a collection.
<c:forEach items="${element}" var="myCollection">
<tr>
<td><c:out value="${element.field}"/></td>
...
</tr>
</c:forEach>
I need an int count variable or boolean odd/even variable to track the row. Then my <tr>
tag would look something like:
<tr class="odd or even depending on the row">
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…