使用jQuery获取集合中点击的元素的索引 [英] Get index of clicked element in collection with jQuery
本文介绍了使用jQuery获取集合中点击的元素的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$('selector')。点击( function(event){
//获取点击的项目的集合中的索引...
});
使用Firebug我看到这样: jQuery151017197709735298827:2
(我点击了第二个元素)
解决方案
这将提醒点击的选择器的索引(从0开始对于第一个):
$('selector')。click(function(){
alert 'selector')。index(this));
});
How do I get the index of clicked item in the code below?
$('selector').click(function (event) {
// get index in collection of the clicked item ...
});
With Firebug I saw this: jQuery151017197709735298827: 2
(I've clicked in the second element).
解决方案
This will alert the index of the clicked selector (starting with 0 for the first):
$('selector').click(function(){
alert( $('selector').index(this) );
});
这篇关于使用jQuery获取集合中点击的元素的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文