本文介绍了JQuery的。每个()向后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery选择页面上的一些元素,然后在DOM移动它们。我遇到的问题是,我需要选择相反的顺序是JQuery的自然要选择所有的元素。例如:
< UL>
<立GT;项目1 LT; /李>
<立GT;项目2'; /李>
<立GT;项目3'; /李>
<立GT;项目4℃; /李>
<立GT;项目5℃/李>
< / UL>
我要选择所有的李项目,然后对他们的。每个()命令,但我想开始第5项,那么第4项等。这可能吗?
解决方案
$($(礼)。get()方法。反向())。每个(函数(){ / * ... * /});
I'm using JQuery to select some elements on a page and then move them around in the DOM. The problem I'm having is I need to select all the elements in the reverse order that JQuery naturally wants to select them. For example:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
I want to select all the li items and use the .each() command on them but I want to start with Item 5, then Item 4 etc. Is this possible?
解决方案
$($("li").get().reverse()).each(function() { /* ... */ });
这篇关于JQuery的。每个()向后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!