案例:jQuery案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript" src="/js/jquery.js"></script>
4
<script type="text/javascript">
5
$(document).ready(function(){
6
  $("button").click(function(){
7
    alert($(".hot").index($("#favorite")));
8
  });
9
});
10
</script>
11
</head>
12
<body>
13
<p>请点击下面的按钮,以获得 id="favorite" 的元素相对于 jQuery 选择器 (class="hot") 的 index:</p>
14
<button>获得 index</button>
15
<ul>
16
<li>Milk</li>
17
<li class="hot">Tea</li>
18
<li class="hot" id="favorite">Coffee</li>
19
</ul>
20
</body>
21
</html>
22