jquery eq()选择器 语法

作用::eq() 选择器选取带有指定 index 值的元素。index 值从 0 开始,所有第一个元素的 index 值是 0(不是 1)。经常与其他元素/选择器一起使用,来选择指定的组中特定序号的元素(如上面的例子)。

语法:$(":eq(index)"

参数:index    必需。规定元素的 index 值。 

jquery eq()选择器 示例

 1 <html>
 2 <head>
 3 <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
 4 <script type="text/javascript"> 
 5   
 6 $(document).ready(function(){
 7     $("p:eq(1)").css("background-color","#B2E0FF");
 8 });
 9 </script> 
10 </head>
11 <body>
12 <html>
13 <body>
14 <h1>Welcome to My Homepage</h1>
15 <p class="intro">My name is Donald</p>
16 <p>I live in Duckburg</p>
17 <p>My best friend is Mickey</p>
18 <div id="choose">
19 Who is your favourite:
20 <ul>
21 <li>Goofy</li>
22 <li>Mickey</li>
23 <li>Pluto</li>
24 </ul>
25 </div>
26 </body>
27 </html>
28 </body>
29 </html>

 

posted @ 2021-11-17 16:10  aixuexi666888  阅读(97)  评论(0编辑  收藏  举报