选择器中项的jQuery索引 [英] jQuery index of item in selector
本文介绍了选择器中项的jQuery索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是伪代码
var index_of_myid = $('.selection').indexOf($('#myid));
不确定这是否正确如果你能理解我正在做什么
not sure if this is right is this possible if you can understand what I'm trying to do
编辑
<div>
<div class="selector"></div>
</div>
<div>
<div class="selector"></div>
</div>
<div>
<div class="selector" id="myid"></div>
</div>
<div>
<div class="selector" id="myid2"></div>
</div>
我只需要知道什么号码选择器是myid
I just need to know what number selector is the myid
推荐答案
当然你的意思是使用jQuery的 index
,而不是 indexOf
JS字符串方法:
Surely you mean to be using jQuery's index
as opposed to the indexOf
JS string method:
var index_of_myid = $('.selection').index($('#myid'));
参见 http://api.jquery.com/index/
这篇关于选择器中项的jQuery索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文