<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> </TH><TH> </TH><TH> </TH><TH> </TH></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
</TABLE>
</BODY>
</HTML>

解决方案 »

  1.   

    alert(document.all.oTable.rows.length+"行")
      

  2.   

    rows
    clos属性
    cells集合可以访问到每个单元格
      

  3.   

    rows
    clos属性
    cells集合可以访问到每个单元格
    ExampleThe following example uses the rows and cells collections to insert a number into each cell of the table. <HTML>
    <SCRIPT LANGUAGE="JScript">
    function numberCells() {
        var count=0;
        for (i=0; i < document.all.mytable.rows.length; i++) {
            for (j=0; j < document.all.mytable.rows(i).cells.length; j++) {
                document.all.mytable.rows(i).cells(j).innerText = count;
                count++;
            }
        }
    }
    </SCRIPT>
    <BODY onload="numberCells()">
    <TABLE id=mytable 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>