jQuery Droppable,删除元素

时间:2022-12-06 15:54:04

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 draggable和droppable将项目放入Dock。使用下面的代码进行删除。

$("#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?

但是我找不到一种方法来获取实际丢弃的元素,所以我可以做一些事情。这可能吗?

1 个解决方案

#1


91  

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)表示draggable被丢弃的droppable。 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();
           }
});

#1


91  

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)表示draggable被丢弃的droppable。 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();
           }
});