<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery.min.js"></script>
<script>
$(function(){
$("tr:eq(0)").css({backgroundColor:"black",color:"#FFF"});
//事件处理方法可以声明参数接收事件(Event)对象
$("tr:gt(0)").on("mouseover mouseout", function(e){
//通过type属性可以获得当前发生的事件类型名称
if(e.type=="mouseover"){
$(this).css("backgroundColor","#CCC")
}else{
$(this).css("backgroundColor","white");
}
})
})
</script>
</head>
<body>
<table width="300" border="1">
<tr>
<td>姓名</td>
<td>成绩</td>
</tr>
<tr>
<td>张三</td>
<td>85</td>
</tr>
<tr>
<td>李四</td>
<td>90</td>
</tr>
<tr>
<td>王五</td>
<td>70</td>
</tr>
<tr>
<td>赵六</td>
<td>95</td>
</tr>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery.min.js"></script>
<script>
$(function(){
$("tr:eq(0)").css({backgroundColor:"black",color:"#FFF"});
//事件处理方法可以声明参数接收事件(Event)对象
$("tr:gt(0)").on("mouseover mouseout", function(e){
//通过type属性可以获得当前发生的事件类型名称
if(e.type=="mouseover"){
$(this).css("backgroundColor","#CCC")
}else{
$(this).css("backgroundColor","white");
}
})
})
</script>
</head>
<body>
<table width="300" border="1">
<tr>
<td>姓名</td>
<td>成绩</td>
</tr>
<tr>
<td>张三</td>
<td>85</td>
</tr>
<tr>
<td>李四</td>
<td>90</td>
</tr>
<tr>
<td>王五</td>
<td>70</td>
</tr>
<tr>
<td>赵六</td>
<td>95</td>
</tr>
</table>
</body>
</html>