zoukankan      html  css  js  c++  java
  • js实现table表格相同内容按需合并

    
    
    uniteTdCells(tableId) {
    var table = document.getElementById(tableId);
    for (let i = 0; i < table.rows.length; i++) {
    for (let c = 0; c < table.rows[i].cells.length; c++) {
    if (c == 0 || c == 1) { //选择要合并的列序数,去掉默认全部合并
    for (let j = i + 1; j < table.rows.length; j++) {
    let cell1 = table.rows[i].cells[c].innerHTML;
    let cell2 = table.rows[j].cells[c].innerHTML;
    if (cell1 == cell2) {
    table.rows[j].cells[c].style.display = 'none';
    table.rows[j].cells[c].style.verticalAlign = 'middle';
    table.rows[i].cells[c].rowSpan++;
    } else {
    table.rows[j].cells[c].style.verticalAlign = 'middle'; //合并后剩余项内容自动居中
    break;
    };
    }
    }
    }
    }
    };
    希望能帮到有需要的人;
  • 相关阅读:
    JQuery中的事件与动画
    JQuery选择器
    初识JQuery
    JavaScript对象及初识面向对象
    JavaScript操作DOM对象
    JavaScript操作BOM对象
    JavaScript基础
    文件管理2
    文件管理
    创建线程
  • 原文地址:https://www.cnblogs.com/fmixue/p/9469379.html
Copyright © 2011-2022 走看看