??

jquery index() ??? ???

??: index() ???? ??? ?? ??? ???? ??? ??? ??? ??? ?????. ??? ??? jQuery ??? ?? DOM ??? ?? ??? ? ????. ??? ?? ? ??? index()? -1? ?????.

?? ??? ??? ? ?? ?? ??? ???: ?? ??? ???? ? ?? ?? ??? ??? ??? ?????.

??: ??$(selector).index()

???? ??? ??? ???: ???? ??? ??? ??? ??? ?????. ??? DOM ?? ?? jQuery ???? ?? ??? ? ????.

??: ??$(selector).index(element)

????:

ParametersDescription
element ?? ?????. ??? ??? ??? ??? ?????. DOM ?? ?? jQuery ???? ? ? ????.

jquery index() ??? ?

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("li").click(function(){
    alert($(this).index());
  });
});
</script>
</head>
<body>
<p>點擊列表項可獲得其相對于同胞元素的 index 位置:</p>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
</body>
</html>
???? ?? ?

??? ????? ??? "???? ??" ??? ?????