我是新手,每日一联,TR隔行换颜色

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus"><TABLE>

  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

 <BODY>
<TABLE id="bb" style="border-collapse:0;border-spacing:0">
<TR>
        <TD>1</TD>
        <TD>1</TD>
        <TD>1</TD>
</TR>
<TR>
        <TD>2</TD>
        <TD>2</TD>
        <TD>2</TD>
</TR>
<TR>
        <TD>3</TD>
        <TD>3</TD>
        <TD>3</TD>
</TR>
<TR>
        <TD>4</TD>
        <TD>5</TD>
        <TD>6</TD>
</TR>
<TR>
        <TD>1</TD>
        <TD>1</TD>
        <TD>1</TD>
</TR>
<TR>
        <TD>2</TD>
        <TD>2</TD>
        <TD>2</TD>
</TR>
<TR>
        <TD>3</TD>
        <TD>3</TD>
        <TD>3</TD>
</TR>
<TR>
        <TD>4</TD>
        <TD>5</TD>
        <TD>6</TD>
</TR>
</TABLE>
<script>
var bb=document.getElementById("bb");

var bbtr=bb.getElementsByTagName("tr");

for (var i=0;bbtr.length;i++ )
{       

       if (i%2==0)
       {
             bbtr[i].style.background="#000066";

       } else {

         bbtr[i].style.background="#CC3333";

           }

           
}
</script>
 </BODY>
</HTML>

作者: 黄一轩   发布时间: 2013-05-15

想要换颜色的加css重class类统一定制属性就好了

作者: jroy   发布时间: 2013-05-16