2010-06-04 81 views
48

一個小問題,希望有一個簡單的答案,我使用jQuery可拖拽和droppable將項目放置到碼頭。使用下面的代碼進行放置。jQuery Droppable,得到元素下降

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

然而,我找不到一種方法來獲取元素實際被刪除,所以我可以做一些事情做。這可能嗎?

回答

90

drop event documentation

當 接受的可拖動的「過度」 下降(的公差範圍內)觸發此事件此 可棄。在回調中,$(this) 表示可拖動的可拖動的 被拖放。 ui.draggable表示可拖動的 。

所以:

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

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

執行積極CSS類需要拆除 – aroos 2014-03-01 05:22:56

+0

對於我來說,這離開元素與拖動狀態,位置:relatative和左/右座標 – 2015-05-15 14:07:29

+0

你究竟是如何選擇doSomething()函數內的可拖動? – 2015-08-18 19:53:28

相關問題