我正在尝试这个,但它的其他部分总是
<c:forEach items="${records}" var="field" varStatus="counter">
<c:choose>
<c:when test="${counter.count mod 2 == 0}">
<div class="classEven">
</c:when>
<c:otherwise>
<div class="classOdd">
</c:otherwise>
</c:choose>
sample text here
</div>
</c:forEach>
这有什么问题?
答案 0 :(得分:21)
您也可以使用${counter.count % 2 == 0}
答案 1 :(得分:1)
test = ${counter.index mod 2 == 0}
答案 2 :(得分:-2)
从html +中分离jstl加上没有数学的艺术类型
<c:set var="row" value="Even" />
<c:forEach items="${records}" var="field" varStatus="counter">
<c:choose>
<c:when test="${row eq 'Odd'}">
<c:set var="row" value="Even" />
</c:when>
<c:otherwise>
<c:set var="row" value="Odd" />
</c:otherwise>
</c:choose>
<div class="class${row}">
sample text here
</div>
</c:forEach>