none
Js表格隔行变色!! RRS feed

  • 问题

  • <!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>
    <script language="javascript" type="text/javascript">
        window.onload = function showtable() {
            var tablename = document.getElementById("mytable");
            var tabletr = tablename.getElementsByTagName("tr");
            for (var i = 0; i <= tabletr.length; i++) {
                if (i % 2 == 0) {
                    tabletr[i].style.backgroundColor = "#FFB584";
                } else tabletr[i].style.backgroundColor = "#FFFFFF";
            }
        }
    </script>

    <table id="mytable" border=0 cellpadding=0 cellspacing=0>
    <tr><td>第1行</td></tr>
    <tr><td>第2行</td></tr>
    <tr><td>第3行</td></tr>
    <tr><td>第4行</td></tr>
    <tr><td>第5行</td></tr>
    </table>
    </body>
    </html>

    效果是有了。但为什么!ff下有错误呢??

    错误: tabletr[i] is undefined

    行:15

    2009年11月16日 7:36

答案