Need Id of BOTH draggable and droppable ID's j

2019-08-04 00:14发布

问题:

I can get the id of the item I have dropped on with the below code, but if i try to change the alert to get the id of the dragged item, nothing happens. e.g. alert(ui.draggable.attr('id') );

 $(function() {
             function dropCallback(e) {
              alert("The firing droppable item was " + e.target.id );
                };


        $("#draggable").draggable({axis:"x"});
         var dropOpts = {
          accept:"#draggable",
          drop:dropCallback,
          greedy:true
        };


        $(".target").droppable(dropOpts);
    }); 

回答1:

Try using...

drop:function(event,ui) {alert($(ui.draggable).attr("id"));}