jQuery Droppable,让元素被删除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2975091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:39:06  来源:igfitidea点击:

jQuery Droppable, get the element dropped

jqueryjquery-uijquery-ui-draggablejquery-ui-droppable

提问by Pez Cuckow

A small question hopefully with a simple answer, I am using jQuery draggable and droppable to place items into a dock. Using the below code for the drop.

一个小问题,希望有一个简单的答案,我正在使用 jQuery 可拖动和可放置将项目放入停靠栏。使用下面的代码进行放置。

$("#dock").droppable({
            drop: function(event, ui) {
                //Do something to the element dropped?!?
            }
        });

However I couldn't find a way to get what element was actually dropped, so I can do something do it. Is this possible?

但是我找不到一种方法来获取实际删除的元素,所以我可以做点什么。这可能吗?

回答by karim79

From the drop event documentation:

drop 事件文档

This event is triggered when an accepted draggable is dropped 'over' (within the tolerance of) this droppable. In the callback, $(this) represents the droppable the draggable is dropped on. ui.draggable represents the draggable.

当接受的可拖动对象被拖放到该可拖动对象上(在其容差范围内)时,将触发此事件。在回调中, $(this) 代表放置可拖动对象的可放置对象。ui.draggable 代表可拖动对象。

So:

所以:

$("#dock").droppable({
     drop: function(event, ui) {
               // do something with the dock
               $(this).doSomething();

               // do something with the draggable item
               $(ui.draggable).doSomething();
           }
});