JSTL之<c:foreach>循环展示table

以前没有将循环用到表格上,在写之前觉得蛮简单,结果自己写的吧,一直有bug,然后找了度娘,下面是成品代码。

<body class="c-body">
<h1 class="bar" align="left">${name }-详细信息</h1>
<c:forEach var="en" items="${enMap }">
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="15" cellspacing="1" bgcolor="#E3E3E3" class="lanf16">
<tr>
<td align="center" bgcolor="#F5F5F5">${en.key }(${fn:length(en.value)})</td>
</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#E3E3E3" class="f12">
<tr>
<c:forEach items="${en.value }" var="env" varStatus="status">
<c:if test="${(status.count) mod 5 != 1}">
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
<c:if test="${(status.count) mod 5==1}">
<tr>
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
</c:forEach>
</tr>
</table>
</c:forEach>
</body>

运行效果如图
[img]http://dl2.iteye.com/upload/attachment/0104/5844/ecf46487-bdc7-3a34-8d1d-50e8125ca87c.png[/img]
其中关键的代码是

<c:forEach items="${en.value }" var="env" varStatus="status">
<c:if test="${(status.count) mod 5 != 1}">
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
<c:if test="${(status.count) mod 5==1}">
<tr>
<td align="center" bgcolor="#FFFFFF">
<a onclick="window.open('http://')" style="cursor: pointer;">${env }</a>
</td>
</c:if>
</c:forEach>

其中mod是取余的。5代表你想要多少个td,即一行你想要多少列,取余的值不能是0,是0会出现第一行会比预期少一行,后面的正常,取余的值为1,则都正常。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值