jQuery indexOf函数? [英] jQuery indexOf function?

查看:95
本文介绍了jQuery indexOf函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在jQuery集中获取元素的位置。

I'm trying to get a location of an element in a jQuery set.

这是我到目前为止所尝试的内容。

Here's what I tried so far.

我希望能够做到这样的事情:

I want to be able to do something like this:

$('ul').find('a').indexOf('.active');

并获取 .active 的位置在 a 的集合中。

And get the location of the .active in the set of a's.

是否有类似的indexOf() jQuery的功能? index()方法不起作用

Is there something like an indexOf() function for jQuery? The index() method doesn't work

推荐答案

如果通过一个jQuery集( $ searchFor )作为另一个jQuery集的 index 方法的参数( $ searchIn )即

if you pass a jQuery set ($searchFor) as an argument to the index method of another jQuery set ($searchIn) i.e.

$searchIn.index($searchFor)

它将在集合<$ c中返回 $ searchFor 的索引$ c> $ searchIn

it will return the index of $searchFor in the set $searchIn

在您的示例中:

$('ul a').index($('ul a.active'));

这篇关于jQuery indexOf函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆