varStatus是<c:forEach>jstl循環標簽的一個屬性,varStatus屬性。
varStatus=“status”事實上定義了一個status名的對象作為varStatus的綁定值。
該綁定值也就是status封裝了當前遍歷的狀態,比如,可以從該對象上查看是遍歷到了第幾個元素:${status.count}
<span style="color: red; font-size: 20px;">${status.count}</span> 寫在 c:forEach 里面.
常見的用法的是<c:forEach var="e" items="${ss.list}" varStatus="status">
<!--實現隔行變色效果-->
<c:if test="${status.count%2==0}" >
<tr style="color: red; font-size: 20px;"/>
</c:if>
<c:if test="${status.count%2!=0}" >
<tr style="color: blue; font-size: 20px;"/>
</c:if>
</c:forEach>
<c:forEach items="${students}" var="s" varStatus="vs"> <tr style='background-color: ${vs.count %2==0 ?"blue":"gray"};'> <td>${s.id }</td> <td>${s.name }</td> <td>${s.age }</td> </tr> </c:forEach>
分行顯示藍色或則灰色。
