0

我做了一个快速列表,您可以将其拖到垃圾桶(将其删除)。

当您按“确定”时,一切正常,并且该项目被删除,因为它被告知。虽然如果您在确认弹出窗口中按“取消”,该项目会显示在垃圾箱中,但我希望它回到它在列表中的位置。

JSFiddle:http: //jsfiddle.net/Gdze8/2/

Javascript:

   $( init )

    function init() {
    $(".contentItem").draggable({
        revert: 'invalid'
    });
    $(".list4").droppable( {
        accept: ".contentItem",

        drop: function(event, ui) {
            ui.draggable.hide();
            if (confirm("Are you sure you want to delete?")){
            ui.draggable.remove();

            bottomInfo ();
        } else {
            ui.draggable.show();
        }
        return false;
        }
    });
    }
4

1 回答 1

4

您将在可拖动对象上添加确认,如果未确认确认等则恢复:

$(".contentItem").draggable({
    revert : function(event, ui) {
        var state = confirm("Are you sure you want to delete?");
        if (state) $(this).remove();
        return !state;
    }
});

小提琴

于 2013-05-14T20:39:00.207 回答