您的位置:首页 > Web前端 > JavaScript

[JSP] c:forEach 输出序号判断奇偶数作不同处理

2015-03-09 13:52 543 查看
关键在于<c:forEach>的varStatus属性,具体代码如下: 

<table width="500" border="0" cellspacing="0" cellpadding="0">

<tr>

    <th>序号</th>

    <th>姓名</th>

</tr>

<c:forEach var="list" items="${list}" varStatus="status">

<tr>

    <td>${ status.index + 1}</td>
    <td>${ student.name}</td>

</tr>

<tr>

<c:if test="${status.index%2==0}">

这是奇数

</c:if>

<c:if test="${status.index%2!=0}">

这是偶数

</c:if>

</tr>

</c:forEach>

</table>

备注:status.index是从0开始的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: