0

以下是我的 jQuery 代码:

$("#remove").click(function(e) {
    $.confirm({
        'title': 'Delete Confirmation',
        'message': 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
        'buttons': {
            'Yes': {
                'class': 'blue',
                'action': function() {
                    $.ajax({
                        'url': "../api/removeHost.php?id=" + $("#id").val(),
                        'success': function(d) {
                            var json = JSON.parse(d);
                            //Display error text
                            if (json[0] == 0) {
                                createMessageDialog("General Error", json[1][1]);
                                //If all is successful reload the listServersBody to reflect the new changes and create the success popup
                            } else {
                                $("#listBody").load(lastPopulateAPICall); //Refresh the search\browse list with the new edits/
                                enableAdd();
                                createMessageDialog("Success", "Successfully removed!");
                            }
                        }
                    });
                }
            },
            'No': {
                'class': 'gray',
                'action': function() {} // Nothing to do in this case. You can as well omit the action property.
            }
        }
    });
});....

function createMessageDialog(title, message) {
    $.confirm({
        'title': title,
        'message': message,
        'buttons': {
            'Ok': {
                'class': 'blue',
                'action': function() {
                    alert('dd');
                }
            },
            'No': {
                'class': 'gray',
                'action': function() {} // Nothing to do in this case. You can as well omit the action property.
            }
        }
    });
}

正在调用 createMessageDialog() 函数,因为正在触发我删除的调试警报。就好像在第一个关闭之前盒子没有足够的时间显示一样。我什至将第一个确认对话框复制到 createMessageDialog 函数中,但无济于事。我正在使用以下确认插件http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/

4

1 回答 1

0

您单击的默认操作可能是刷新页面。

$("#remove").click(function(e) {
    e.preventDefault(); // cancel the click
    ...
于 2012-07-19T13:41:37.417 回答