0

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

//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
                }

            }
        });
4

1 回答 1

-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/

于 2012-05-14T07:55:06.250 回答