您的位置:首页 > 其它

关于前台合并获取后台动态table中数据相同的单元格的问题;th td合并

2016-11-24 11:14 1401 查看
将下面的这个算法,直接复制到你的js里面, 最后面的那个是你获取table的id,然后传入合并哪一列就行了。

//合并单元格算法
jQuery.fn.rowspan = function(colIdx) { //封装的一个JQuery小插件
return this.each(function(){
var that;
$('tr', this).each(function(row) {
$('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
if (that!=null && $(this).html() == $(that).html()) {
rowspan = $(that).attr("rowSpan");
if (rowspan == undefined) {
$(that).attr("rowSpan",1);
rowspan = $(that).attr("rowSpan"); }
rowspan = Number(rowspan)+1;
$(that).attr("rowSpan",rowspan);
$(this).hide();
} else {
that = this;
}
});
});
});
}

$("#sjdltjList")这个是table的id,你要合并哪一行就在后面传哪一行的数字  .rowspan(0);
$(function() {
$("#sjdltjList").rowspan(0);  //传入的参数是对应的列数从0开始,哪一列有相同的内容就输入对应的列数值
$("#sjdltjList").rowspan(1);
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐