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