jQuery實現(xiàn)的簡單獲取索引功能示例
本文實例講述了jQuery實現(xiàn)的簡單獲取索引功能。分享給大家供大家參考,具體如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>chabaoo.cn 獲取當前點擊的元素在原來集合中的索引</title>
<style type="text/css">
li {
height: 25px;
line-height: 25px;
background: rgba(0,0,0,0.5);
border-bottom: 1px solid red;
}
a {
text-decoration: none;
font-size: 16px;
}
</style>
</head>
<body>
<div>
<ul>
<li>
<a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<div class="index">
0
</div>
</a>
</li>
<li>
<a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<div class="index">
1
</div>
</a>
</li>
<li>
<a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<div class="index">
2
</div>
</a>
</li>
<li>
<a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<div class="index">
3
</div>
</a>
</li>
<li>
<a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<div class="index">
4
</div>
</a>
</li>
</ul>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".index").on("click",function(){
var $target = $(this);
console.log($(".index").index($target));
});
});
</script>
</body>
</html>
使用在線HTML/CSS/JavaScript代碼運行工具 http://tools.jb51.net/code/HtmlJsRun測試運行結(jié)果如下:

更多關(guān)于jquery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery操作DOM節(jié)點方法總結(jié)》、《jquery常用操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery操作xml技巧總結(jié)》及《jQuery擴展技巧總結(jié)》
希望本文所述對大家jquery程序設(shè)計有所幫助。
相關(guān)文章
JQuery調(diào)webservice實現(xiàn)郵箱驗證(檢測是否可用)
JQuery調(diào)webservice實現(xiàn)郵箱驗證:判斷郵箱是否存在如果不存在提示可以使用否從提示該郵箱已存在請重新輸入,感興趣的朋友可以參下哈,希望對你有所幫助2013-05-05
使用jQuery實現(xiàn)的網(wǎng)頁版的個人簡歷(可換膚)
點擊姓名會顯示她的基本詳細信息,點擊切換皮膚,會更改皮膚和字體大小感興趣的朋友可以參考下本文如何使用jQuery實現(xiàn)的網(wǎng)頁版的個人簡歷2013-04-04
jQuery+ajax實現(xiàn)鼠標單擊修改內(nèi)容的思路
這篇文章主要介紹了jQuery+ajax實現(xiàn)鼠標單擊修改內(nèi)容的思路及核心代碼,需要的朋友可以參考下2014-06-06
基于$.ajax()方法從服務(wù)器獲取json數(shù)據(jù)的幾種方式總結(jié)
下面小編就為大家分享一篇基于$.ajax()方法從服務(wù)器獲取json數(shù)據(jù)的幾種方式總結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
jQuery+canvas實現(xiàn)的球體平拋及顏色動態(tài)變換效果
這篇文章主要介紹了jQuery+canvas實現(xiàn)的球體平拋及顏色動態(tài)變換效果,通過jQuery結(jié)合html5的canvas技術(shù)調(diào)用時間函數(shù)實時進行數(shù)學(xué)運算,最終實現(xiàn)球體平拋及顏色動態(tài)變換的效果,需要的朋友可以參考下2016-01-01
基于jquery animate操作css樣式屬性小結(jié)
昨天突然有網(wǎng)友問我animate()方法可以來操作所有css屬性嗎?是的,我告訴他可以的。不過,在此有需要注意點需要大家搞清楚。接下來通過本篇文章給大家介紹基于jquery animate操作css樣式屬性小結(jié),對jquery animate css相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-11-11

