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

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程序設計有所幫助。

相關文章

最新評論