<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>

解决方案 »

  1.   

    <table id="wc" width="150" border="1">
      <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr>
    </table>
    <script type="text/javascript">
    window.onload = function () {
    var wc = document.getElementById("wc").getElementsByTagName("tbody")[0];
    alert("行数:" + wc.rows.length + "\n" + "第一行列数:" + wc.rows[0].cells.length);
    };
    </script>
      

  2.   

    rows 和cell 分别代表表格的行和列的集合!
    在后面加上 .length就可以得到行和列的数量!
      

  3.   

    alert("行数:" + wc.rows.length + "\n" + "第一行列数:" + wc.rows[0].cells.length);