js合并同列单元格相同内容

function tableMergeCell(col) {
        //col可指定列
        let tdContent = []
        let numbers = 1
        let indexs = 0
        $('tbody tr').each(function (index, item) {
            //记入第一行数据
            if (index == 0) {
                tdContent.push($('td:eq(' + col + ')', $(item)).text())
            } else {
                if (tdContent.indexOf($('td:eq(' + col + ')', $(item)).text()) != -1) {
                    //与上一行内容相同,隐藏单元格
                    //值得注意的是 如果用了$.remove()就会对其他列的处理造成影响
                    $('td:eq(' + col + ')', $(item)).css('display', 'none')
                    //累加需要合并相同单元格数量
                    numbers++
                    $('td:eq(' + col + ')', $('tbody tr:eq(' + indexs + ')')).attr('rowspan', numbers)
                } else {
                    //与上一行内容不相同,清空数据
                    tdContent = []
                    numbers = 1
                    indexs = index
                    tdContent.push($('td:eq(' + col + ')', $(item)).text())
                }
            }
        })
    }

 

    原文作者:imHere·
    原文地址: https://blog.csdn.net/qq_31754523/article/details/104815632
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞