jquery colspan rowspan

来源:互联网 发布:mac单windows系统 编辑:程序博客网 时间:2024/05/17 01:18
(function ($) {  
    $.fn.extend({  
        //表格合并单元格,colIdx要合并的列序号,从0开始  
        "rowspan": function (colIdx,thOrtd) {
            if(!thOrtd){
                thOrtd='td';
            }
            return this.each(function () {
                var that;  
                $('tr', this).each(function (row) {  
                    $(thOrtd+':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;  
                        }  
                    });  
                });  
            });  
        }  
    });  
 

})(jQuery);


(function ($) {  
    $.fn.extend({  
        //表格行合并单元格,rowIdx要合并的行序号,从0开始  
        "colspan": function (rowIdx,thOrtd) {  
            if(!thOrtd){
                thOrtd='td';
            }
            return this.each(function () {  
                var that;
                  $(this).find('tr:eq(' + rowIdx + ')').find(thOrtd).each(function(col){
                        if (that != null && $(this).html() == $(that).html()) {  
                            colspan = $(that).attr("colspan");  
                            if (colspan == undefined) {  
                                $(that).attr("colspan", 1);  
                                colspan = $(that).attr("colspan");  
                            }  
                            colspan = Number(colspan) + 1;  
                            $(that).attr("colSpan", colspan);  
                            $(this).hide();  
                        } else {  
                            that = this;  
                        }
                });
            });  
        }  
    });  
 
})(jQuery);

0 0
原创粉丝点击