foreach循环遍历 行合并


<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<style type="text/css">

table{
border: 1px solid black;
border-collapse: collapse;
}
td{
border: 1px solid black;
text-align: center;
}
</style>
</head>
<body>
<table align="center" width="650px">
<tr bgcolor="#CCFFFF">
<td>序号</td>
<td colspan="2">项目</td>
<td>1月</td>
<td>2月</td>
<td>3月</td>
<td>x年合计</td>
</tr>
<c:forEach items="${configApp}" var="configAppname" varStatus="index">
<c:set var="ca" value="${configAppname.configProjectType.projectName}"/>
<c:set var="count" value="0"/>
<c:forEach items="${configApp}" var="configApps">
<c:if test="${configApps.configProjectType.projectName==ca}">
<c:set var="count" value="${count+1}"/>
</c:if>
</c:forEach>
<tr>
<td>${index.count}</td>
<td class="hebing">${configAppname.configProjectType.projectName}</td>
<td>${configAppname.appName}</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
</tr>
</c:forEach>

<tr>
<td></td>
<td colspan="2">项目收入合计</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
</tr>
</table>
</body>
</html>
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script> $(function(){ $('.hebing').each(function(index, element) { if(!$(this).hasClass('hide')) { var next=$(this).parent('tr').next('tr').children('.hebing');//下一个合并的对象
            $(this).attr('rowspan',1); while($(this).text()==next.text()) { $(this).attr('rowspan',parseInt($(this).attr('rowspan'))+1); next.hide(); next.addClass('hide'); next=next.parent('tr').next('tr').children('.hebing');//下一个合并的对象
 } } }); }); </script>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM