如果 droppable 已经包含该元素,jquery 恢复拖动
我面临着拖拽的问题。这是小提琴。 http://jsfiddle.net/dJyUQ/16/
有 4 个框(A、B、C ,D)并且所有都是可丢弃的。 “.item”div 是可拖动的,并且可以放置在 4 个 droppable 中的任何一个上。
我只想将一份物品副本放置在一个可放置物品上。因此,当我尝试再次将项目的副本放置在同一个可放置对象上时,它不允许我这样做。目前我已经插入了一个警报。但我想取消或恢复拖动。
请帮助我,因为我认为我错过了一些东西。我搜索了 jquery ui 拖放插件但找不到任何东西。
I am facing the dragging problem. Here's the fiddle.
http://jsfiddle.net/dJyUQ/16/
There are 4 boxes (A, B, C, D) and all are droppables.
".item" div is draggable and can be dropped on any of the 4 droppables.
I want just one copy of item to be dropped on one droppable. So that when I attempt to again drop copy of item on the same droppable it wouldn't allow me. Currently I have inserted an alert. But I want to cancel or revert dragging.
Please help me as I think I am missing something. I searched jquery ui dragging and droppable plugin but could not find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的放置代码更改为:
http://jsfiddle.net/dJyUQ/18/
Change your drop code to be this:
http://jsfiddle.net/dJyUQ/18/
您可以使用这篇博客文章中的这个技巧:使用 < code>revert: function(socketObj)
这是一个工作示例:http://jsfiddle.net/dJyUQ/16/
[编辑]理查德的答案要好得多。我将留下关于在
revert
方法中使用函数的答案(不过我发现这是一个好主意,请查看这篇文章)。You can use this trick from this blog article: using
revert: function(socketObj)
Here is a working example: http://jsfiddle.net/dJyUQ/16/
[EDIT] Richard's answer is far better. I'll leave my answer for the use of a function within the
revert
method (I found this was a good idea though, have a look at the article).将放置代码更改为以下内容
change the drop code to the following