使用jQuery获取已经相互删除的元素的值?

时间:2022-11-29 20:55:41

I have the following jQuery:

我有以下jQuery:

  $(document).ready(function(){
    $(".element").draggable();
    $(".element").droppable({
      drop: function() { 
        alert('dropped');
      }
    });
  });

Anything with the class of 'element' can be manipulated and dragged around the page. I want to be able to find the html contents of the element that is being dragged and the element that is being dropped and use them where "alert('dropped');" is, so I could do something like:

任何具有“元素”类的东西都可以在页面上进行操作和拖动。我希望能够找到被拖动的元素的html内容和被删除​​的元素,并在“alert('dropped');”中使用它们。是的,所以我可以这样做:

alert(firstelement+ ' was dropped on ' +secondelement);

Any Ideas?

1 个解决方案

#1


You need to add parameters to your drop callback.

您需要为drop回调添加参数。

drop : function(event, ui) {
   var droppable = $(this);
   var draggable = ui.draggable;

   alert(droppable.attr('id') + " was dropped on " + draggable.attr('id'));
}

http://jqueryui.com/demos/droppable/#event-drop

#1


You need to add parameters to your drop callback.

您需要为drop回调添加参数。

drop : function(event, ui) {
   var droppable = $(this);
   var draggable = ui.draggable;

   alert(droppable.attr('id') + " was dropped on " + draggable.attr('id'));
}

http://jqueryui.com/demos/droppable/#event-drop