主要运用JQ中的层级选择器和基本过滤器
层级选择器
$(a b),选择从a到b的所有选项
基本过滤器
$(b: even) 选择b中的偶数项,odd是奇数
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
</title>
<link rel="stylesheet" href="myCSS.css" />
<script type="text/javascript" src="../JQ/jquery-1.8.3.js" ></script>
<script>
$(function(){
//1.获取奇数行
//$("tbody tr:even").css("background-color","white")
//2.获取偶数行
//$("tbody tr:odd").css("background-color","pink")
$("tbody tr:even").addClass("even");
$("tbody tr:odd").addClass("odd");
})
</script>
</head>
<body>
<body>
<table border="1" width="500px" height="50px" align="center" 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>