// 基、偶數列新增 css
$("#people tr:odd").addClass("odd");
$("#people tr:even").addClass("even");
// 為 id 等於 people 的 table元件 的 每一個 row 附加 mouseenter 和 mouseout 事件
$("#people tr").hover(
function(){
$(this).addClass("enter"); // 觸發 mouseenter 事件 新增 css
},
function(){
$(this).removeClass("enter"); // 觸發 mouseleave 事件 移除 css
}
);
<table id="people">
<tbody>
<tr><td>1</td><td>jason</td></tr>
<tr><td>2</td><td>thomas</td></tr>
<tr><td>3</td><td>kert</td></tr>
<tr><td>4</td><td>jay</td></tr>
</tbody>
</table>
#people { width:98%; border-collapse:collapse; }
#people th, #people td{ border: silver 1px solid; text-align:center; }
.odd{background-color:#CCCCFF;}
.even{background-color:#BFFFFF;}
.enter{background-color:#FFCCFF;}