我为drag n drop delete编写了一个代码。用户可以将项目拖动到垃圾箱然后来确认消息,如果确认删除它,并且如果用户不确认删除该项目需要转到原来的位置,请帮帮我
//drag code
var a = 3;
$('#dragZone .box,#dragZone .box1,#dragZone .box2').draggable({containment:".invitemain"}, {
start:function (event, ui) {
$(this).css("z-index", a++);
},
stop:function () {
var id = $(this).attr("mid");
var x = $(this).position().left;
var y = $(this).position().top;
var z = $(this).css("z-index");
//send request to server to save the position
$.get('/users/savecodes?mid=' + id + '&x=' + x + '&y=' + y + '&z=' + z, function (data) {
//alert(data);
});
}
});
//drop code
$("#trash").droppable({
tolerance: 'touch',
drop: function(ev, ui) {
var answer = confirm('Permanently delete this item?');
if(answer){
//call some ajax for delete
$(ui.draggable).remove();
}
else{
//move to original position
}
}
});
答案 0 :(得分:-1)
function stopDrag{
$("#trash").draggable({ cancel: "button" });
}
并调用你的函数
$(ui.draggable).remove();
}
else{
stopDrag();
}
我认为这可能有效我自己没试过但是我查看了这个链接:http://jqueryui.com/demos/draggable/#option-cancel所以试一试
并查看此链接,这也正是您在寻找的内容:http://www.ericbieller.com/2010/06/24/how-to-create-a-simple-drag-and-drop-with-jquery/