jQuery实现表格的隔行变色高亮显示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>隔行变色高亮显示</title></title>
<style type="text/css">
table{
text-align: center;
font-weight: bold;
}
tr{
height: 32px;
}
</style>
<script type="text/javascript" src="js/jquery-3.2.1.min.js" ></script>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" width="400">
<tr>
<td>编号</td>
<td>姓名</td>
<td>年龄</td>
</tr>
<tr>
<td>1</td>
<td>张三</td>
<td>18</td>
</tr>
<tr>
<td>2</td>
<td>李四</td>
<td>19</td>
</tr>
<tr>
<td>3</td>
<td>王五</td>
<td>20</td>
</tr>
<tr>
<td>4</td>
<td>赵六</td>
<td>21</td>
</tr>
<tr>
<td>5</td>
<td>钱七</td>
<td>22</td>
</tr>
</table>
</body>
<script type="text/javascript">
$('table tr:first').css({'background':'#694d9f'});
$('table tr:even').not('table tr:first').css({'background':'#888'});
$('table tr:odd').css({'background':'#ccc'});
$('table tr').not('table tr:first').hover(
function(){
color=$(this).css('backgroundColor');
$(this).css({'background':'yellow'});
},
function(){
$(this).css({'background':color});
}
);
</script>
</html>