如何找到在jQuery的数组元素的indexOf? [英] How to find indexOf element in jQuery array?
本文介绍了如何找到在jQuery的数组元素的indexOf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个选择
var allNodes = $("a.historyEntry");
var errorNodes = $("a.historyEntry.error");
我想找到第一个错误节点之前的节点,所以我需要找到第一个错误节点的指数,该怎么办呢?
I would like to to find a node before first error node, so I need to find an index of first error node, how to do it?
我试图使用inArray方法,但它并没有为这个工作
I tried to use inArray method, but it doesn't work for this
$.inArray(allNodes, errorNodes.first())
或
$.inArray(allNodes, $(errorNodes.first()))
有没有快速的方法来做到这一点jQuery的或者我必须使用循环?
Is there any fast way to do it in jQuery or do I have to use for loop?
推荐答案
指数()
的?
这就像的indexOf
...只是没有中
...它返回的元素的索引如果它存在,和-1,如果它不
It's like indexOf
... but just without the Of
... it returns the index of the element if it exists, and -1 if it doesn't.
这篇关于如何找到在jQuery的数组元素的indexOf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文