我有一个可拖拽的div,它需要放在一个可拖放的东西上。如果它被正确删除,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??
}
}
}); 发布于 2010-08-02 21:37:20
我也有同样的问题,
您可以简单地这样做:
item.css({"top":0, "left":0});提示: draggable有相对位置。
发布于 2009-08-31 13:47:05
我不太熟悉jquery --但我建议使用prototype框架(以及脚本)--在prototype中,你完全可以达到这个效果。
发布于 2009-08-31 13:50:26
如果你能猜到它在fail块中的原始位置,只需使用选择器找到它,并使用操作函数将其从当前位置移除并将其移动到旧位置。
如果需要,也许可以在拖动时存储原始位置(父索引和子索引),然后在失败时将其移回该位置
https://stackoverflow.com/questions/1357427
复制相似问题