如果你想通過每一行(<tr>
),明知/識別行(<tr>
),並通過各行(<tr>
)中的每一列(<td>
)迭代,那麼這是要走的路。
var table = document.getElementById("mytab1");
for (var i = 0, row; row = table.rows[i]; i++) {
//iterate through rows
//rows would be accessed using the "row" variable assigned in the for loop
for (var j = 0, col; col = row.cells[j]; j++) {
//iterate through columns
//columns would be accessed using the "col" variable assigned in the for loop
}
}
如果你只是想通過細胞(<td>
),忽略你在哪一行,那麼這是要走的路。
var table = document.getElementById("mytab1");
for (var i = 0, cell; cell = table.cells[i]; i++) {
//iterate through cells
//cells would be accessed using the "cell" variable assigned in the for loop
}
可能'row.cells [J]。 j ++)',對嗎? – maerics 2010-06-17 20:31:10
謝謝你...複製粘貼錯誤。 – 2010-06-17 20:31:58
ex2,table.cells isnt瀏覽器兼容 – EricG 2012-12-14 13:14:31