jquery 合并table表格行或列

合并行

$("#tableId").find("tr").each(function(rowIndex) {
   
    var cells = $(this).find("td");
    cells.each(function(cellIndex) {
   
        var cell = $(this);
        var prevRowCell = table.find("tr:eq(" + (rowIndex - 1) + ")").find("td:eq(" + cellIndex + ")");
        if (prevRowCell.html() === cell.html()) {
   
            cell.remove();
            prevRowCell.attr("rowspan", (prevRowCell.attr("rowspan") || 1) + 1);
        }
    });
});

合并列

<script>
$("#tableId").find("tr").each(function(rowIndex) {
   
    var cells = $(this).find("td"); 
    cells.each(function(cellIndex) {
   
        var cell = $(this);
        var prevRowCell = table.find("tr:eq(" + (rowIndex - 1) + ")").find("td:eq(" + cellIndex + ")");
        if (prevRowCell.html() === cell.html()) {
   
            cell.remove();
            prevRowCell.attr("rowspan", (prevRowCell.attr("rowspan") || 1) + 1);
            prevRowCell.attr("colspan", (prevRowCell.attr("colspan") || 1) + 1);
        }
    });
});

👇觉得有帮助的朋友可以支持下作者哦,您的鼓励是我创作的最大动力,如有开发问题可联系作者
请添加图片描述

相关推荐

  1. vue项目- el-table表格合并

    2024-01-16 15:50:06       40 阅读
  2. vue3中el-table实现表格合计

    2024-01-16 15:50:06       66 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-16 15:50:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-16 15:50:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-16 15:50:06       82 阅读
  4. Python语言-面向对象

    2024-01-16 15:50:06       91 阅读

热门阅读

  1. springboot整合webSocket(看完即入门)

    2024-01-16 15:50:06       53 阅读
  2. (二)模板templates

    2024-01-16 15:50:06       53 阅读
  3. openharmony 编译LLVM编译器基础架构

    2024-01-16 15:50:06       56 阅读
  4. 数据结构和算法笔记

    2024-01-16 15:50:06       53 阅读
  5. Linux下防火墙相关命令整理【转】

    2024-01-16 15:50:06       51 阅读
  6. Python使用函数输出指定范围内Fibonacci数的个数

    2024-01-16 15:50:06       53 阅读
  7. DelayQueue

    2024-01-16 15:50:06       36 阅读