var trs  =  document.getElementsByTagName("tr");
alert(trs[0]);
页面也就是一个table
返回为undefined,不太清楚为什么,网上说NodeList可以直接当数组用的。

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <table>
            <tr>
                <td>
                </td>
            </tr>
        </table>
        <script>
            var trs = document.getElementsByTagName("tr");
            alert(trs[0]);    </script>
    </body>
    </html>没有问题啊。。页面加载完才能调用其元素
      

  2.   

    跟真正的数组还是有差别的,只是可以通过下标获得,不能push,pop
      

  3.   

    [Quote=引用 1 楼  的回复:]
    谢谢,确实是这样,我是先写js再写html的,谢谢了。