欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jquery index()方法 獲取相應(yīng)元素索引值

 更新時間:2012年10月12日 00:27:08   作者:  
昨天做一個Jqery效果,要獲取相應(yīng)元素的索引值,暈,又忘記了?,F(xiàn)在記錄下來,以后再次忘記好查怎么獲取相應(yīng)元素的索引值
index([subject])方法,返回值:Number(從0開始計數(shù))
index()方法返回指定元素相對于其他指定元素的 index 位置。注釋:如果未找到元素,index() 將返回 -1。
復(fù)制代碼 代碼如下:

<html>
<head>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert($(".hot").index($("#favorite")));
});
});
</script>
</head>
<body>
請點(diǎn)擊下面的按鈕,以獲得 id="favorite" 的元素相對于 jQuery 選擇器 (class="hot") 的 index:
<button>獲得 index</button>
<ul>
<li>Milk</li>
<li class="hot">Tea</li>
<li class="hot" id="favorite">Coffee</li>
</ul>
</body>
</html>

相關(guān)文章

最新評論