表格内容相同单元格合并

//表格内容相同单元格合并 colIdx列索引
jQuery.fn.rowspan = function(colIdx) { //封装的一个JQuery小插件
    return this.each(function(){
        var that;
        var rowspan;
        $('tr', this).each(function(row) {
            $('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
                if (that!=null && $(this).html() == $(that).html()) {
                    /*上一行*/
                    var prev_name=$(this).parent().prev().find('td:last').text()
                    /*var prev_name_arr=prev_name.split('-');*/
                    /*当前行*/
                    var pro_name=$(this).parent().find('td:last').text()
                   /* var pro_name_arr=pro_name.split('-')*/
                    rowspan = $(that).attr("rowSpan");
                    if (rowspan == undefined) {  /*如果是列第一个*/
                        $(that).attr("rowSpan",1);
                        rowspan = $(that).attr("rowSpan");
                    }
                    if(prev_name!=pro_name){   /*如果当前行的值与上一行的值不相等*/
                        that = this;                         /*就把当前行记录进行比较*/
                    }else{
                        rowspan = Number(rowspan)+1;
                        $(that).attr("rowSpan",rowspan);
                        $(this).hide();
                    }
                } else {
                    that = this;
                }
            });
        });
    });
}

你可能感兴趣的:(表格内容相同单元格合并)