JQuery .each() 向后 [英] JQuery .each() backwards

查看:24
本文介绍了JQuery .each() 向后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JQuery 选择页面上的一些元素,然后在 DOM 中移动它们.我遇到的问题是我需要以 JQuery 自然想要选择它们的相反顺序选择所有元素.例如:

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>

我想选择所有 li 项并对它们使用 .each() 命令,但我想从第 5 项开始,然后是第 4 项等等.这可能吗?

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 .each() 向后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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