如果您想遍历每一行(
<tr>),知道/识别该行(
<tr>),并遍历每一行(
<td>)的每一列(
<tr>),那么这就是要走的路。
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 } }如果您只是想遍历cell(
<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}


