将元素从一个div内拖动到另一个div [英] Drag element from inside one div into another

查看:783
本文介绍了将元素从一个div内拖动到另一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将一个元素从一个div内拖动到另一个div.

I want to have the capability of dragging an element from inside one div into another.

jQuery UI 可拖动可投放,但它们似乎只能使用position:relative可视地操纵元素,而不会在DOM中移动它们.如果可以的话,我似乎找不到任何例子或想办法.

jQuery UI draggable and droppable, but they seem to only manipulate the elements visually, using position:relative without moving them through the DOM. If they can, I can't seem to find an example or figure out how.

如果我有两个简单的div,例如:

Say if I have two simple divs such as:

<div id="firstDiv">
    <div id="moveMe">I need to be moved to secondDiv</div>
</div>
<div id="secondDiv">
</div>

如何将#moveMe#firstDiv拖放到#secondDiv?

推荐答案

它不是在操纵DOM,因为据我所知,这就是他们的目的.

It is not manipulating DOM because as far as I know that's what they are designed to do.

如果您想操纵DOM,则可以采取以下措施

If you want to manipulate the DOM then you can the following trick

您可以在 THEN 时使用 helper选项.删除元素,阅读坐标,然后使用 jQuery Clone 函数克隆原始的放入放置区域#secondDiv 然后,然后删除原始元素#firstDiv > div#moveMe

You can use helper option, THEN when the element is dropped, read the co-ordinates and then use jQuery Clone function to clone your original div#moveMe to the drop area #secondDiv AND THEN remove the original element #firstDiv > div#moveMe

这篇关于将元素从一个div内拖动到另一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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