遍历换行算法(table里面循环tr,td,灵活处理行和列)

本文介绍了一种处理HTML表格中tr和td的方法,实现灵活的行和列遍历,适用于动态换行和算法操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<table border="0" cellspacing="12px" cellpadding="0" style="margin:0 auto;">
	<%	
	//美丽前言的图片和标题
	List beautyInfoSome= getBeautyInfoSome(info[1]);
	int h = beautyInfoSome.size() / 3;
	if (beautyInfoSome.size() % 3 > 0) {
		h++;
	}	
	int j = 0;
	for (int k = 0; k < h; k++) {
	%>
		<tr>
		<!--第一个TABLE -->
		<%
		for(j = k * 3; j < (k + 1) * 3; j++) {
			if (beautyInfoSome.size() > j) {
				String[] infoInner = (String[])beautyInfoSome.get(j);
				if(info[1].equals(infoInner[0])){
				%>
				<td>
					<table border="0" style="margin:5px 5px 5px 5px;">
						<tr>
							<td class="td1"><a target="_blank" href="beauty_status_view.jsp?beauty_info_id=<%=infoInner[4]%>"><img style="margin-left:12px;width:270px;height:215px;cursor:pointer;" src="/mainpage/topic/beauty/upload/<%=infoInner[3]%>" alt=""/></a>
							</td>
						</tr>
						<tr>
							<td><p class="p4"><%=infoInner[1]%></p>
								<p class="p5 right"><%=infoInner[2]%></p>
								<p class="p5 right">[<a style="color: #FF5705" target="_blank" href="beauty_status_view.jsp?beauty_info_id=<%=infoInner[4]%>">查看详情</a>]</p>
							</td>
						</tr>
					</table>
				</td>	
				<%}	
			}
		}				
		%>
		</tr>
	<%}%>
</table>



另一种

  <table border="0" cellspacing="20px" cellpadding="0" style="margin:0 auto;">
			<!-- col -->
			<tr>
		      <%
		      	//
		      	List voteRankList = null; 	
					    voteRankList = getBeautyVoteRank();
	
				String[] beautyName=null;
				String[] beautyNameLast=null;
				for (int i = 0; i < voteRankList.size(); i++) {
					String[] info = (String[])voteRankList.get(i);
					if(i != 0 && i % 5 ==0){
				%>
				<!-- 关键 -->
					</tr>
					<tr>
				<!-- 关键 -->
				<%	
					}
				%>			
				<td>
					<!-- 数据info -->
					<table border="0" style="margin:5px 5px 5px 5px;">
						<tr>
						  <td class="td1"><a target="_blank" href="beauty_status_view.jsp?beauty_info_id=<%=info[4]%>"><img class="img" src="/mainpage/topic/beauty/upload/<%=info[3]%>" alt="" /></a></td>
						</tr>
						<tr>
						<td>
							<div style="width:100%; height:40px; line-height:20px;">
								<div class="p5 s2"><%=beautyNameLast[1]%><%=isEmptyStr(beautyName[1])?"":"-"+beautyName[1]%></div>
							</div>	
              				<!--团队的姓名无-->
							<div style="width:100%; height:40px; line-height:20px;">
								<div class="p5">第 <%=i+1%>名 <span class="s2 mar_left">得票数:<%=isEmptyStr(info[5])?"0":info[5]%></span></div>
							</div> 
						</td>
						</tr>
					</table><!-- end info  -->
				</td>
		<%
			}
		%>		
			</tr><!-- end col -->
    </table>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值