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;
};
}
}
}
}
};
希望能帮到有需要的人;

相关文章:

  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案