合并table指定列

原创 飞鸟渡林 随笔 js方法 609阅读 2014-08-27 11:17:39 举报

[code]
/
id:合并table的ID
colIndex:需要合并的列
/
rowspan = function (id, colIndex) {
var table = document.getElementById(id);
var count = 1;
var modifyRow = null;
var rows = table.rows;
for (var i = 0; i < rows.length; i++)
{
//赋值
if (modifyRow == null) {
modifyRow = rows[i].cells[colIndex];
}
else {
//值相同
if (modifyRow.textContent == rows[i].cells[colIndex].textContent) {
++count;
rows[i].cells[colIndex].remove();
} else {
//值不同
if (count == 1) {
modifyRow = rows[i].cells[colIndex];
} else {
modifyRow.setAttribute("rowspan", count);
modifyRow.style.textAlign = "center";
//重置
modifyRow = rows[i].cells[colIndex];
count = 1;
}
}
}
//最后一个
if (i == rows.length-1)
{
if (count != 1)
{
modifyRow.setAttribute("rowspan", count);
modifyRow.style.textAlign = "center";
}
}

}

};[/code]

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复