1. 程式人生 > >jquery表格隔行換色

jquery表格隔行換色

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>使用jQuery完成表格隔行換色</title>
		<link type="text/css" rel="stylesheet" href="../css/style.css"></link>
		<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
		<script type="text/javascript">
			$(function(){
				$("tbody tr:even").css("background","yellow");
				$("tbody tr:odd").css("background","red"); 
				
				/* $("tbody tr:even").addClass("even");
				$("tbody tr:odd").addClass("odd"); */
				
			});
		</script>
		
	</head>
	<body>
		<table border="1" width="500" height="50" align="center" id="tbl" id="tbl">
			<thead>
				<tr>
					<th>編號</th>
					<th>姓名</th>
					<th>年齡</th>
				</tr>
			</thead>
			<tbody>
				<tr >
					<td>1</td>
					<td>張三</td>
					<td>22</td>
				</tr>
				<tr >
					<td>2</td>
					<td>李四</td>
					<td>25</td>
				</tr>
				<tr >
					<td>3</td>
					<td>王五</td>
					<td>27</td>
				</tr>
				<tr >
					<td>4</td>
					<td>趙六</td>
					<td>29</td>
				</tr>
				<tr >
					<td>5</td>
					<td>田七</td>
					<td>30</td>
				</tr>
				<tr >
					<td>6</td>
					<td>汾九</td>
					<td>20</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>