1 <!-- 有时候需要获得匹配元素相对于其同胞元素的索引位置,此时可以用index()方法获取 --> 2 <!DOCTYPE html> 3 <html lang="en"> 4 <head> 5 <meta charset="UTF-8"> 6 <title>Document</title> 7 <script type="text/javascript" src="../jquery-1.12.4.min.js"></script> 8 <script type="text/javascript"> 9 $(function(){ 10 var $li = $('.list li'); 11 // alert($li.eq(3).index()); 12 var iDex = $li.filter('.myli').index(); 13 alert(iDex); 14 }); 15 </script> 16 </head> 17 <body> 18 <ul class="list"> 19 <li>1</li> 20 <li>2</li> 21 <li>3</li> 22 <li>4</li> 23 <li class="myli">5</li> 24 <li>6</li> 25 <li>7</li> 26 <li>8</li> 27 </ul> 28 </body> 29 </html>