varStatus是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>
</c:if>
1111111
</tr>
</c:forEach>
有比如:必须
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 标签
<form action="finish.do" method="post">
姓名:${stepForm.name }<br>
产品:
<c:forEach items="${stepForm.productId}" var="p" varStatus="vs">
产品${p }
<c:if test="${vs.count != fn:length(stepForm.productId)}">
,
</c:if>
</c:forEach>
<br>
地址:${stepForm.address }<br>
<input type="submit" value="确认">
</form>
本文详细介绍了JSTL循环标签中varStatus属性的使用方法,并通过实例展示了如何利用varStatus来实现隔行变色等效果,以及如何在循环中获取当前遍历的状态。
1980

被折叠的 条评论
为什么被折叠?



