jQuery-移动元素并返回其确切的先前位置吗? [英] jQuery - move element and return to its exact previous location?

查看:84
本文介绍了jQuery-移动元素并返回其确切的先前位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery将元素从DOM中的一个位置移动到另一个位置.旁边有与原始容器相同的元素,那么如何存储其确切的先前位置,以便它返回原位置?这是一个例子...

I'm trying to use jQuery to move an element from one location to another in the DOM. There are elements identical to the originating container alongside it, so how do I store its exact previous location so it will return back to it? Here's an example...

<div class="container"></div>
<ul>
    <li></li>
    <li><div class="move">Content</div></li>
    <li></li>
    <li><div class="move">Content</div></li>
    <li></li>
</ul>

...移动" div分别移动到容器" div,然后通过jQuery .appendTo()返回事件的先前位置.如何通过检测每个移动" div的移动位置(它在DOM中相对于文档的确切位置,或其他指定的父容器)来确保返回到其先前的确切位置?

...the "move" divs are individually moving to the "container" div, then back to their previous location on an event via jQuery .appendTo(). How do I ensure each "move" div returns to its exact previous location by detecting where it was moved from (its exact location in the DOM relative to the document, or an otherwise specified parent container)?

由于我正在处理的特定情况下的列表项是彼此的完全重复(结构上),并且在其各自元素中具有唯一内容,因此我已更正了divs上的类.同样,将移动" div移动回其原始位置的事件是在其中单击的按钮.已移动的元素如何知道一次移动后要移回的位置(特别是如何知道列表中的哪个列表项)?

I have corrected the classes on the divs since the specific case I'm working with has the list items being exact duplicates of one another (structurally), with unique content within their respective elements. Also, the event to move a "move" div back to its original location is a button clicked within it. How does the moved element know where to move back to once moved (specifically, how does it know which list item within the list)?

推荐答案

您可以clone它们,append它们,最后hide原始div,并返回remove克隆的div和原始的.

you can clone them, append them , and finally hide the original div, and in return remove the cloned div and show the original.

这篇关于jQuery-移动元素并返回其确切的先前位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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