获取jquery中元素的索引
我在表行中有以下html元素:获取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> 但无论该元素被重复多少次,或者我单击了哪一次,
<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));
});