function ChangeColor()
{
for(var i=0;i<document.all.trRole.length;i++)
{
if(document.all.trRole[i] == null)
{
tr = document.all.trRole;
}
else
{
tr = document.all.trRole[i];

}
if(i%2)//奇数行的颜色--淡兰色
{
tr.style.backgroundColor = "EFF1F6";
tr.style.color = "000000";
}
else//偶数行的颜色--没有颜色
{
tr.style.backgroundColor = "";
tr.style.color = "000000";
}
}
}trRole是行的id,有什么不明白的你再问问我,不过,应该没有什么问题。

解决方案 »

  1.   

    function ChangeColor(oTab)
    {
        for (i=0;i<oTab.rows.length;i++)
        {
           if (i/2==0)
             oTab.rows[i].style.backgroundColor = "";
           else
             oTab.rows[i].style.backgroundColor = "000000";
        }
    }
    你试试呢?
      

  2.   

    经测试代码:更正上述错误<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" name="tb" id="tb">
      <tr>
        <td>111111111</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>222222222</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>d</td>
        <td>ddddddddd</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>dddddssss</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>fffffff</td>
      </tr>
    </table>
    <script language="JavaScript">
    ChangeColor(document.all.tb)
    function ChangeColor(oTab)
    {
        int_bool = true
        for (i=0;i<oTab.rows.length;i++)
        {
       if (int_bool)
           {
             oTab.rows[i].style.backgroundColor = "";
     int_bool = false
           }
       else
           {
         oTab.rows[i].style.backgroundColor = "000000";
     int_bool = true
       }
        }
    }</script>
    </body>
    </html>