2012-02-03 85 views
6

我想這一點,但它要else部分總是JSP MOD操作不工作

<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> 

這有什麼錯呢?

+2

你試過用'$ {(counter.count模2)== 0}'? – 2012-02-03 12:05:46

+0

是的,它的工作現在..謝謝JB – user965884 2012-02-03 12:16:20

回答

19

你也可以使用${counter.count % 2 == 0}

-2

分居JSTL從HTML +加上沒有數學你顯得撲朔迷離類型

<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> 
1
test = ${counter.index mod 2 == 0}