jQuery實現的簡單獲取索引功能示例
更新時間:2018年06月04日 12:04:54 作者:前端愛我
這篇文章主要介紹了jQuery實現的簡單獲取索引功能,涉及jQuery事件響應及元素索引獲取相關操作技巧,需要的朋友可以參考下
本文實例講述了jQuery實現的簡單獲取索引功能。分享給大家供大家參考,具體如下:
<!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.dbjr.com.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測試運行結果如下:
更多關于jquery相關內容感興趣的讀者可查看本站專題:《jQuery操作DOM節(jié)點方法總結》、《jquery常用操作技巧匯總》、《jQuery常見事件用法與技巧總結》、《jQuery操作json數據技巧匯總》、《jQuery操作xml技巧總結》及《jQuery擴展技巧總結》
希望本文所述對大家jquery程序設計有所幫助。
相關文章
JQuery調webservice實現郵箱驗證(檢測是否可用)
JQuery調webservice實現郵箱驗證:判斷郵箱是否存在如果不存在提示可以使用否從提示該郵箱已存在請重新輸入,感興趣的朋友可以參下哈,希望對你有所幫助2013-05-05基于$.ajax()方法從服務器獲取json數據的幾種方式總結
下面小編就為大家分享一篇基于$.ajax()方法從服務器獲取json數據的幾種方式總結,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01jQuery+canvas實現的球體平拋及顏色動態(tài)變換效果
這篇文章主要介紹了jQuery+canvas實現的球體平拋及顏色動態(tài)變換效果,通過jQuery結合html5的canvas技術調用時間函數實時進行數學運算,最終實現球體平拋及顏色動態(tài)變換的效果,需要的朋友可以參考下2016-01-01