jquery index() ??? ???
??: index() ???? ??? ?? ??? ???? ??? ??? ??? ??? ?????. ??? ??? jQuery ??? ?? DOM ??? ?? ??? ? ????. ??? ?? ? ??? index()? -1? ?????.
?? ??? ??? ? ?? ?? ??? ???: ?? ??? ???? ? ?? ?? ??? ??? ??? ?????.
??: ??$(selector).index()
???? ??? ??? ???: ???? ??? ??? ??? ??? ?????. ??? DOM ?? ?? jQuery ???? ?? ??? ? ????.
??: ??$(selector).index(element)
????:
Parameters | Description |
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>點(diǎn)擊列表項(xiàng)可獲得其相對(duì)于同胞元素的 index 位置:</p> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> </body> </html>
??? ????? ??? "???? ??" ??? ?????