【发布时间】:2009-08-31 13:18:11
【问题描述】:
我有一个可拖动的 div,需要将其拖放到 droppable 上。如果它被正确删除,则 droppable 会调用 AJAX 请求。如果可拖动对象没有有效的 id 或 AJAX 请求失败,则应将可拖动对象恢复到其原始位置。 jQuery可以做到这一点吗?!
非常感谢任何帮助!
$("div.draggable").livequery(function(){
$(this).draggable({
revert: 'invalid',
distance: 20
})
});
$("#trash").droppable({
tolerance: 'touch',
drop: function(event, ui)
{
var item = ui.draggable;
var id = item.attr('id');
if (id)
{
$.ajax(
{
type: "POST",
url: "delete.php",
data: "id=" + id,
success: function(html)
{
if (html)
{
item.remove();
}
else
{
// FAILED AFTER AJAX
// is it possible to revert the draggable from here??
}
}
});
}
else
{
// FAILED BEFORE AJAX
// is it possible to revert the draggable from here??
}
}
});
【问题讨论】:
标签: php jquery jquery-ui drag-and-drop