表格隔行变色和鼠标滑过变色
****不会影响到tr中的th****
jquery代码
<script> $(document).ready(function(){ $("#mytable tr:even td").css("background","#ccc"); $("#mytable tr:even td").attr("bg","#ccc"); $("#mytable tr:odd td").attr("bg","#fff"); $("#mytable tr td").hover(function(){ $(this).parent().find("td").css("background","#000") },function(){ var bgc = $(this).attr("bg"); $(this).parent().find("td").css("background",bgc) }); }) </script>
HTML代码
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="mytable"> <tr> <th>1</th> <th>2</th> <th>4</th> <th> </th> </tr> <tr> <td>1</td> <td>2</td> <td>4</td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table>