Js和jQuery获取dom点击click事件下标index
<!-- DOM List --> <div class="dot"> <span class=""></span> <span class=""></span> <span class=""></span> <span class=""></span> <span class="cur"></span> </div>
效果图:
// 纯js获取点击下标 var dotObj = document.querySelectorAll('.gallery-area .slide .dot span'); for (var i = 0; i < imgSize; i++) { dotObj[i].onclick = function(e) { var index = Array.prototype.indexOf.call(dotObj, this); console.log(index); } }
// jQuery 获取点击下标 var dotObj = $('.gallery-area .slide .dot span') dotObj.click(function() { console.log($(this).index()); });
更多实例应用扫码体验:
相关推荐
84483065 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
tztzyzyz 2020-07-05
delmarks 2020-06-28
89510194 2020-06-27
牵手白首 2020-06-14
tztzyzyz 2020-05-31
81463166 2020-05-17
88570299 2020-05-17
delmarks 2020-05-17
donghongbz 2020-05-15
tztzyzyz 2020-05-15
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%&qu
牵手白首 2020-05-14
Chriswang 2020-04-30
83510998 2020-05-03