用<c:forEach>标签嵌套实现多选框的动态排版

<fieldset>
	<legend>经营种类</legend>
	
	<table class="list" width="100%">
	<tbody>					
		<c:forEach items="${jypzList}" var="item" step="4" varStatus="status">
			<tr style="text-align: left;  ">
				<c:forEach items="${jypzList}" var="initem" begin="${status.index}" end="${status.index+3}">
					<c:if test="${not empty initem.id}">
						<td>
							<input type="checkbox" name="jypz" value="${initem.id}"  />${initem.name}
						</td>
					</c:if>
				</c:forEach>
			</tr>
		</c:forEach>
	</tbody>
	</table>
</fieldset>

  实现以下效果。每行显示四个复先框

(1)、设置循环的步长。

<c:forEach items="${jypzList}" var="item" step="4" varStatus="status">

(2)、设置嵌套循环的起始(begin,end)

<c:forEach items="${jypzList}" var="initem" begin="${status.index}" end="${status.index+3}">

(3)、编辑时,查询数据库,将数据库中存在的选项选中

<c:if test="${not empty initem.id}">
	<td>
		<input type="checkbox" name="jypz" value="${initem.id}"  />${initem.name}
	</td>
</c:if>

猜你喜欢

转载自hhj12321.iteye.com/blog/1630935