如果你想通过每一行(<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