alert(document.getElementsByTagName("tr").length);

解决方案 »

  1.   

    谢谢楼上,那如果这个页面还有别的table,那里面也有动态的数据,怎么办呢?
      

  2.   

    也就是,我想查指定table中的tr的个数,该如何写呢?...
      

  3.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>new page</title>
    </head>
    <body>
    <table id=t>
        <tr>
    <td>id</td>
    <td>name</td>
    <td>sex</td>
    <td>mail</td>
        </tr>
    </table>
    </body>
    <script>
    var len=document.getElementById("t").rows.length;//还有其他的table,那就给这个table指定一个id就可以了
    if(len==1){
    alert("没有读取到数据!");
    }else{
    alert("读取到"+(len-1)+"条数据!");
    }
    </script>
    </html>