我刚刚开始这样做,但我想知道如何采用下面非常简单的示例并进行修改,以便如果可拖动的 div 已经放置在可放置的 div 上,它不会触发警报。
<script type="text/javascript">
$(function () {
$("#draggable-1").draggable();
$("#draggable-2").draggable();
$("#droppable").droppable({
drop: function (event, ui) {
var currentId = $(ui.draggable).attr('id');
if (currentId == "draggable-1") {
$(this)
// would like to prevent this if draggable is already dropped!
alert("Adding Item #1.")
} else {
$(this)
alert("Adding Item #2.")
}
}
});
});
</script>
<table width="100%"><tr><th>Draggable</th><th>Order Section</th><tr><td>
<div id="draggable-1">
<p>Item #1</p>
</div>
<div id="draggable-2">
<p>Item #2.</p>
</div>
<div id="droppable">
<p>Add Your Item</p>
</div>