取消操作如果“取消”;作为对confirm()的响应

Undo action if "cancel" is pressed in response to confirm()

本文关键字:取消 confirm 响应 如果 操作      更新时间:2023-09-26

我做了一个快速列表,你可以把它拖到垃圾桶(这样就可以删除它)。

当你按下"ok"时,一切都工作了,并且项目被告知要删除。虽然如果你按"取消"键来确认弹出,项目显示在垃圾桶中,而不是我希望它回到它在列表中的位置。

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;
        }
    });
    }

您将在可拖动项上添加确认,如果未确认则返回确认等:

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

小提琴