本篇文章给大家分享的是有关使用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.jb51.net 获取当前点击的元素在原来集合中的索引</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>
以上就是使用jQuery怎么实现一个获取索引功能,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。