码迷,mamicode.com
首页 > 其他好文 > 详细

通用表格合并单元格

时间:2015-01-04 12:03:15      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

1.源码: 

/**

 * 合并表格的列
 * @param {String} tableId要合并的表格的id
 * @param {int} fCol开始的列
 * @param {int} eCol结束的列
 * @return void
 */
function mergCol(tableId, fCol, eCol) {
var oTable = $(tableId);
if (!$chk(oTable)/*!oTable*/) {
return;
}
var oTBody = oTable.tBodies[0];
var oRows = oTBody.rows;
if (oRows.length == 0) {
return;
}
var rowspan = 1;
for ( var j = fCol; j <= eCol; j++) {
var oRow = oRows[0];
for ( var i = 1; i < oRows.length; i++) {
var oNextRow = oRows[i];
if ((oRow.cells[j] != null && oNextRow.cells[j] != null)
&& (oRow.cells[j].innerHTML == oNextRow.cells[j].innerHTML)) {
rowspan++;
oRow.cells[j].merg = rowspan;
oNextRow.cells[j].merg = -1;
} else {
oRow = oNextRow;
rowspan = 1;
}
}
}
for ( var i = oRows.length - 1; i >= 0; i--) {
for ( var j = eCol; j >= fCol; j--) {
var oRow = oRows[i];
if (oRow.cells[j] != null && oRow.cells[j].merg == -1) {
oRow.cells[j].parentNode.removeChild(oRow.cells[j]);
} else {
if (oRow.cells[j] != null && oRow.cells[j].merg > 0) {
oRow.cells[j].rowSpan = oRow.cells[j].merg;
}
}
}
}
}

应用:mergCol (‘edit-0‘,0,0);

通用表格合并单元格

标签:

原文地址:http://www.cnblogs.com/nxblog/p/4200696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!