将元素从一个div内拖动到另一个div [英] Drag element from inside one div into another
问题描述
我希望能够将一个元素从一个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 div
s 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屋!