您的位置:首页 > Web前端 > JQuery

jquery 动态表格合并

2017-05-18 17:02 441 查看
$.fn.extend({

    //表格合并单元格,colIdx要合并的列序号,从0开始

    "rowspan": function (colIdx) {

        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;

                    }

                });

            });

        });

    }

  });

  $("#testlist").rowspan(1); //第一列合并
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: