</table>
第二种
<script type="text/javascript"> $(document).ready(function () { //方式一 //$("#tblContent tr:nth-child(even)").css({ "background-color": "#E4F5FF" }); //方式二 $("#tblContent tr:even").css("background-color", "#fff"); //奇数行 $("#tblContent tr:odd").css("background-color", "#E4F5FF");//偶数行 }); function cells_color() { $("#tblContent tr").mouseover(function () { $(this).css({ "background-color": "#87CEEB" }); }).mouseout(function (event) { var $index = $(this).index(); if ($index % 2 == 0) { $(this).css({ "background-color": "#fff" }); } else { $(this).css({ "background-color": "#E4F5FF" }); } }); } </script>
<table id="tblContent" onmouseover="cells_color()" onmouseout="cells_color()" border="1" cellpadding="1" cellspacing="0" onmouseover="cells_color()" onmouseout="cells_color()"> <tbody id="ttr"> <tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr> <tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr><tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr><tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr><tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr><tr> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> <td>1</td> </tr> </tbody> </table>
<script>
function bgChange(obj){
obj.bgColor=obj.bgColor==""?"#0099ff":"";
}
</script>
<table width="80%" border="1">
<tr onclick="bgChange(this)"><td>a</td><td>a</td></tr>
<tr onclick="bgChange(this)"><td>a</td><td>a</td></tr>
<tr onclick="bgChange(this)"><td>a</td><td>a</td></tr>
</table>