jQuery选择器02
选择器 | 实例 | 选取 |
:first | $("p:first") | 第一个<p>元素 |
:last | $("p:last") | 最后一个元素 |
:even | $("tr:even") | 所有偶数<tr>元素 |
:odd | $("tr:odd") | 所有奇数<tr>元素 |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p:first").css("background-color","#B2E0FF");
});
</script>
</head>
<body>
<h1>欢迎来到音乐网站!</h1>
<p class="intro">My name is YanHSama!</p>
<p>Can you tell me ?</p>
<p>I like music very much!</p>
<div id="choose">
Which is your favourite:
<ul>
<li>music</li>
<li>book</li>
<li>sport</li>
</ul>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p:last").css("background-color","#B2E0FF");
});
</script>
</head>
<body>
<h1>欢迎来到音乐网站!</h1>
<p class="intro">My name is YanHSama!</p>
<p>Can you tell me ?</p>
<p>I like music very much!</p>
<div id="choose">
Which is your favourite:
<ul>
<li>music</li>
<li>book</li>
<li>sport</li>
</ul>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("tr:even").css("background-color","#B2E0FF");
});
</script>
</head>
<body>
<p>欢迎来到音乐网站!</p>
<p class="intro">My name is YanHSama!</p>
<p>Can you tell me ?</p>
<p>I like music very much!</p>
<div id="choose">
Which is your favourite:
<ul>
<li>music</li>
<li>book</li>
<li>sport</li>
<li>climb</li>
</ul>
</div>
<div id="info">
<table border="1">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
</table>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("tr:odd").css("background-color","#B2E0FF");
});
</script>
</head>
<body>
<p>欢迎来到音乐网站!</p>
<p class="intro">My name is YanHSama!</p>
<p>Can you tell me ?</p>
<p>I like music very much!</p>
<div id="choose">
Which is your favourite:
<ul>
<li>music</li>
<li>book</li>
<li>sport</li>
<li>climb</li>
</ul>
</div>
<div id="info">
<table border="1">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
<tr>
<td>d</td>
<td>的</td>
<td>发</td>
<td>g</td>
<td>y</td>
<td>g</td>
</tr>
</table>
</div>
</body>
</html>