您可以做的是将您的可拖动对象包装在div
您也制作的 a 中droppable
:
<div id="originalposition">
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="draggable2" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
</div>
然后您可以执行以下操作:
$(function() {
$("#draggable").draggable({ revert: 'invalid' });
$("#draggable2").draggable({ revert: 'invalid' });
$("#originalposition").droppable({
drop: function(event,ui) {
$("#droppable").removeClass("ui-state-highlight").addClass("ui-widget-header").html("<p>Drop here</p>");
}
});
$("#droppable").droppable({
drop: function(event, ui) {
$(this).addClass("ui-state-highlight").find("p").html("Dropped!");
},
accept: function(dropElem) {
//dropElem was the dropped element, return true or false to accept/refuse it
return (!$(this).hasClass("ui-state-highlight") && $(dropElem).hasClass("ui-widget-content"));
}
});
});
在这里拉小提琴。