o=document.getElementById("tableID")
for(i=0;i<o.rows.length;i++)
{
for(j=0;j<o.rows[i].cells.length;j++)
{
alert(o.rows[i].cells[j].innerText)
}
}

解决方案 »

  1.   

    ExampleThis example shows how to use the rows collection on the table object and the cells collection to insert a number into each cell of the table. Hide Example<HTML>
    <SCRIPT LANGUAGE="JScript">
    function numberCells() {
        var count=0;
        for (i=0; i < document.all.oTable.rows.length; i++) {
            for (j=0; j < document.all.oTable.rows(i).cells.length; j++) {
                document.all.oTable.rows(i).cells(j).innerText = count;
                count++;
            }
        }
    }
    </SCRIPT>
    <BODY onload="numberCells()">
    <TABLE id=oTable border=1>
    <TR><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH></TR>
    <TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
    </TABLE>
    </BODY>
    </HTML> 
      

  2.   

    <table id="tbl">
    <tr>
    <td>1</td><td>2</td>
    </tr>
    </table>
    <button onclick="find(0,1)">find</button>
    <script language="javascript">
    function find(row,cell){alert(tbl.rows[row].cells[cell].innerText);}
    </script>