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>www.dhdzp.com 獲取當前點擊的元素在原來集合中的索引</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)文章
40個有創(chuàng)意的jQuery圖片和內(nèi)容滑動及彈出插件收藏集之二
在網(wǎng)頁的首頁或圖片專題頁面很多地方都會用到圖片滑動插件來循環(huán)切換多張圖片,并且用戶可以點擊左右按鈕來切換圖片。2011-12-12
解析Jquery中如何把一段html代碼動態(tài)寫入到DIV中(實例說明)
本篇文章是對在Jquery中把一段html代碼動態(tài)寫入到DIV中的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友可以參考下2013-07-07
jquery中ajax函數(shù)執(zhí)行順序問題之如何設(shè)置同步
這篇文章主要介紹了jquery中ajax函數(shù)執(zhí)行順序問題之如何設(shè)置同步,需要的朋友可以參考下2014-02-02
jquery實現(xiàn)的讓超出顯示范圍外的導航自動固定屏幕最頂上
經(jīng)常會遇到這樣的情況,當頁面展示內(nèi)容過長時,想點導航切換欄目,就得把滾動條拉回到頂上,這樣操作總不太人性化,能不能讓導航超出顯示范圍外時自動貼在屏幕最頂上呢?答案肯定是能的。如果不太明白,把滾動條拉到下面點,看下我博客是效果就明白了。2011-09-09
jQuery 如何實現(xiàn)一個滑動按鈕開關(guān)
本文給大家分享一段jquery代碼實現(xiàn)滑動按鈕開關(guān)的效果,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的的朋友參考下2016-12-12
jquery實現(xiàn)適用于門戶站的導航下拉菜單效果代碼
這篇文章主要介紹了jquery實現(xiàn)適用于門戶站的導航下拉菜單效果代碼,可實現(xiàn)鼠標滑過菜單項實現(xiàn)下拉列表顯示效果的功能,非常具有實用價值,需要的朋友可以參考下2015-08-08

