jQuery选择器:选择两个元素,然后选择所有元素 [英] jQuery selectors: select two elements, and all elements in between

查看:108
本文介绍了jQuery选择器:选择两个元素,然后选择所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UL内部有大量LI,每个LI都有唯一的ID.

I have a load of LIs inside an UL, and each one has a unique ID.

给出两个ID,最好是选择两个对应的LI()之间的所有LI的最佳方法?

Given two IDs, what's the best way to select the two corresponding LIs, and all the LIs in between?

谢谢!

推荐答案

http://api.jquery.com /nextUntil/

给出一个表示一组DOM元素的选择器表达式,.nextUntil()方法在DOM树中搜索这些元素的后继元素,并在到达与该方法的参数匹配的元素时停止.返回的新jQuery对象包含以下所有同级,直到但不包括与.nextUntil()参数匹配的同级.

Given a selector expression that represents a set of DOM elements, the .nextUntil() method searches through the successors of these elements in the DOM tree, stopping when it reaches an element matched by the method's argument. The new jQuery object that is returned contains all following siblings up to but not including the one matched by the .nextUntil() argument.

如果选择器不匹配或没有提供选择器,则将选择以下所有同级;在这种情况下,它会选择没有提供过滤器选择器时与.nextAll()方法相同的元素.

If the selector is not matched or is not supplied, all following siblings will be selected; in these cases it selects the same elements as the .nextAll() method does when no filter selector is provided.

从jQuery 1.6起,可以将DOM节点或jQuery对象而不是选择器传递给.nextUntil()方法.

As of jQuery 1.6, A DOM node or jQuery object, instead of a selector, may be passed to the .nextUntil() method.

该方法可以选择接受第二个参数的选择器表达式.如果提供了此参数,则将通过测试元素是否匹配来对其进行过滤...

The method optionally accepts a selector expression for its second argument. If this argument is supplied, the elements will be filtered by testing whether they match it...

这篇关于jQuery选择器:选择两个元素,然后选择所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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