各行換色
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");
});
各行換色