html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link href="css/demo2.css" rel="stylesheet" />
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/demo2.js"></script>
</head>
<body>
<table>
<tr><th>姓名</th><th>学号</th><th>年龄</th><th>性别</th></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
<tr><td>张三</td><td>001</td><td>20</td><td>男</td></tr>
</table>
</body>
</html>
css:
* {
padding: 0px;
margin: 0px;
}
table {
border: solid 1px #ccc;
border-collapse: collapse;
width: 200px;
height: 400px;
}
th, td {
border: solid 1px #ccc;
text-align: center;
}
.odd {
background-color: #adf7e7;
}
.even {
background-color: #7ff5f0;
}
js:
/// <reference path="jquery-1.10.2.min.js" />
$(function () {
$("tr:odd").addClass("odd");
$("tr:even").addClass("even");
});