我写了一个拖放删除的代码。用户可以将项目拖到垃圾箱然后出现确认消息,如果确认删除它,并且如果用户不确认删除该项目需要回到原来的位置,请帮帮我
//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
}
}
});