jquery 合并相同单元格

//合并内容相同单元格
function mergeTableCell(table_id, table_colnum) {
    _w_table_firsttd = "";
    _w_table_currenttd = "";
    _w_table_SpanNum = 0;
    _w_table_Obj = $("#" + table_id + " tr td:nth-child(" + 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();
                _w_table_firsttd.attr("rowSpan", _w_table_SpanNum);
            } else {
                _w_table_firsttd = $(this);
                _w_table_SpanNum = 1;
            }
        }
    });
}
//调用
$(function()
  mergeTableCell(表明,列数(从1开始))
});
posted @ 2012-09-11 16:39  hedan  阅读(96)  评论(0)    收藏  举报