jsp頁面上實現表格的豎向合併。 01 /** 02 * 合併表格的列 03 * @param {String} tableId要合併的表格的id 04 * @param {int} fCol開始的列 05 * @param {int} eCol結束的列 06 * @return void 07 */ 08 function mergCol(tableId, fCol, eCol) { 09 var oTable = $(tableId); 10 if (/*!$chk(oTable)*/!oTable) { 11 return; 12 } 13 var oTBody = oTable.tBodies[0]; 14 var oRows = oTBody.rows; 15 if (oRows.length == 0) { 16 return; 17 } 18 for (var j = fCol; j <= eCol; j++) { 19 var oRow = oRows[0]; 20 var rowspan = 1; 21 for (var i = 1; i < oRows.length; i++) { 22 var oNextRow = oRows[i]; 23 if (oRow.cells[j].innerHTML == oNextRow.cells[j].innerHTML) { 24 rowspan++; 25 oRow.cells[j].merg = rowspan; 26 oNextRow.cells[j].merg = -1; 27 } else { 28 oRow = oNextRow; 29 rowspan = 1 30 } 31 } 32 } 33 34 for (var i = oRows.length - 1; i >= 0; i--) { 35 for (var j = eCol; j >= fCol; j--) { 36 var oRow = oRows[i]; 37 if (oRow.cells[j].merg == -1) { 38 oRow.cells[j].parentNode.removeChild(oRow.cells[j]); 39 } else { 40 if (oRow.cells[j].merg > 0) { 41 oRow.cells[j].rowSpan = oRow.cells[j].merg; 42 } 43 } 44 } 45 } 46 }