1. 程式人生 > >foreach循環遍歷 行合並

foreach循環遍歷 行合並

jquer ddc his sta add src foreach app stat

<%@ 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>

foreach循環遍歷 行合並