您的位置:首页 > 其它

合并表格中同一列中相同的内容

2014-05-19 00:00 260 查看
摘要: 把表格中同一列中相同的内容合并成一行

<script type="text/javascript">
$(function(){

_w_table_rowspan("#apply_company",1);//第一个参数:表格的ID
//第二个参数:表格的第一列(根据自己需求而定)

});
function _w_table_rowspan(_w_table_id,_w_table_colnum){
_w_table_firsttd = "";
_w_table_currenttd = "";
_w_table_SpanNum = 0;
//注意1:  tr th: (根据自己需求修改)
_w_table_Obj = $(_w_table_id + " tr th:nth-child(" + _w_table_colnum + ")");
_w_table_Obj.each(function(i){
if(i==0){
_w_table_firsttd = $(this);
_w_table_SpanNum = 1;
}else{
_w_table_currenttd = $(this);
if(_w_table_firsttd.text()==_w_table_currenttd.text()){
_w_table_SpanNum++;
_w_table_currenttd.hide(); //remove();
_w_table_firsttd.attr("rowSpan",_w_table_SpanNum);
}else{
_w_table_firsttd = $(this);
_w_table_SpanNum = 1;
}
}
});
}

</script>

<table id="apply_company" cellpadding="0" cellspacing="0" width="100%" border="0"  >
<tr>
<th></th>    //这里与 注意1 相对应
</tr>

</table>

最后效果如下:


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  合并列