Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取jquery中元素的索引_Jquery_Dom - Fatal编程技术网

获取jquery中元素的索引

获取jquery中元素的索引,jquery,dom,Jquery,Dom,我在表行中有以下html元素: <a class="btn small small-red-button" ng-click="addTicket(d, schedule.schedule_id )" ><i class="glyphicon glyphicon-plus state"></i> <span class="text">Add Ticket</span></a> 但无论该元素被重复多少次,或者我单击了哪一次,

我在表行中有以下html元素:

<a class="btn small small-red-button" ng-click="addTicket(d, schedule.schedule_id )" ><i class="glyphicon glyphicon-plus state"></i> <span class="text">Add Ticket</span></a>

但无论该元素被重复多少次,或者我单击了哪一次,索引总是弹出为0。有人能告诉我为什么吗?

请按照@adeneo comment结束这个问题

代码

$(document).on("click", ".btn.small", function() {
   alert($(".btn.small").index(this));
});

我不敢苟同:--请提供一个可复制的问题。您可能需要
$(“.btn.small”)。索引(此)
,因为按钮不是同级按钮,而是在不同的行中。@Juhana。。对不起。实际上@Adeneo的答案解决了我的问题,现在一切正常。如果不是评论的话,你会将其标记为正确答案。你在帖子中提到“尝试获取每个重复元素的索引”。我想这把回答的人弄糊涂了。
$(document).on("click", ".btn.small", function() {
   alert($(".btn.small").index(this));
});