請在這裏看到一個演示。 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