码迷,mamicode.com
首页 > 其他好文 > 详细

table按某列进行分组

时间:2014-10-17 23:20:35      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   java   for   sp   on   cti   html   

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function () {
$(‘#ipId‘).click(function () {
var tdArr = $(‘.cls‘);


var oldObj = tdArr[0];
var rowspan = 1;
for (var i = 1; i < tdArr.length; i++) {
var newObj = tdArr[i];
if ($(oldObj).html() == $(newObj).html()) {
rowspan++;
$(newObj).remove();
$(oldObj).attr("rowspan", rowspan);
}
else {
$(oldObj).attr("rowspan", rowspan);
rowspan = 1;
oldObj = newObj;
}
}
});
});

</script>
</head>
<body>
<input type="button" value="button" id="ipId" />
<table border="1" id="grouptable">

<tbody>
<tr>
<td class="cls">A</td>
<td>AA</td>
<td>AAA</td>
</tr>
<tr>
<td class="cls">A</td>
<td>BB</td>
<td>BBB</td>
</tr>
<tr>
<td class="cls">A</td>
<td>CC</td>
<td>CCC</td>
</tr>
<tr>
<td class="cls">A</td>
<td>DD</td>
<td>DDD</td>
</tr>
<tr>
<td class="cls">B</td>
<td>CC</td>
<td>CCC</td>
</tr>
<tr>
<td class="cls">B</td>
<td>DD</td>
<td>DDD</td>
</tr>
</tbody>
</table>
</body>
</html>

table按某列进行分组

标签:http   io   ar   java   for   sp   on   cti   html   

原文地址:http://www.cnblogs.com/qfkobe24/p/4032225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!