请在这里看到一个演示。 http://jsfiddle.net/wgstudio/CqNfZ/2/如何知道合并行或列的html表的实际列和行索引
我想合并单元格(0,0)和单元格(1,0)在html talbe,它工作在一个常规的表。
该代码isbelow。
function() {
var table = $("#table1");
var rowIndex = 0;
var colIndex = 0;
var actionCell =$($(table.children().children()[rowIndex]).children()[colIndex]); //Cell1
var tr = table.children().children()[rowIndex + 1];
var toBeRemoved = $($(tr).children()[colIndex]);//Cell4
toBeRemoved.remove();
rowSpan = toBeRemoved.attr("rowSpan") == undefined ? 1 : parseInt(toBeRemoved.attr("rowSpan"), 10);
actionCell.attr("rowspan", (actionCell.attr("rowSpan") == undefined ? 1 : parseInt(actionCell.attr("rowSpan"), 10)) + rowSpan);
}
但如果表是这样的:
<table id="table2" style=" width: 100%;">
<tr>
<td rowspan="2">cell_1</td>
<td rowspan="2">cell_2cell_5</td>
<td>cell_3</td>
</tr>
<tr>
<td>cell_6</td>
</tr>
<tr>
<td>cell_7</td>
<td>cell_8</td>
<td>cell_9</td>
</tr>
</table>
(0,0),(0,1)合并的细胞,当我想合并(0,0) “小区1” 和(2,0)“Cell7”,如何通过js代码找到“cell 7”?
希望我解释清楚。
非常感谢。
比尔
这将如何从用户角度在更真实的世界环境中工作?您的简化演示仅适用于第一行和第二行。可以给你更多灵活的解决方案,如果underrstand将如何实施 – charlietfl