自定义确认对话框无法正常工作

Custom Confirmation dialog doesn't work properly

本文关键字:工作 常工作 确认 对话框 自定义      更新时间:2023-09-26

我已经创建了自定义对话框,如Alert和ConfirmDialog与Bootstrap和Jquery。

这是示例: http://jsfiddle.net/eb71eaya/

问题 - 在回调中我进行了 ajax 调用,如果它返回 true - 我显示状态成功的警报,否则 - 错误。但是,当请求进行删除时,此警报不会显示。(在示例中,我不发出 ajax 请求,只是显示警报,但这也不起作用。

    function getEsrbAlertDialog(title, msg, callBack, obj) {
    var esrbAlertDialog = $('#esrb-dialog');
    if (esrbAlertDialog.length == 0) {
        esrbAlertDialog = getEsrbDialog(title, msg);
    } else {
        $('.modal-title', esrbAlertDialog).html(title);
        $('.modal-body', esrbAlertDialog).html(msg);
    }
    $('.modal-footer div', esrbAlertDialog).empty();
    $('.modal-footer div', esrbAlertDialog).append('<button class="btn btn-primary pull-right close-btn">Close</button>');
    $('.close-btn', esrbAlertDialog).unbind('click').click(function () {
        if (typeof callBack === "function") {
            todo = callBack(obj);
        }
        esrbAlertDialog.modal('hide');
    });
    return esrbAlertDialog;
};

我想在确认对话框关闭时执行回调。


更新:我理解这样的逻辑:当用户单击"确定"按钮时,必须关闭对话框。当它已经关闭时,触发事件"hidden.bs.modal",它必须执行callBack。但是回调在确认对话框完成隐藏之前执行。

这一行:

esrbConfirmationDialog.modal('hide');

正在隐藏第二个对话框。


编辑:两个对话框都使用与引用相同的div:

var esrbAlertDialog = $('#esrb-dialog');

创建单独的对话框,一个用于警报,一个用于确认。

只需替换它。警报功能到下面的代码,即只需添加 e.preventDefault();

this.Alert = function (dialogMsg, callBack, obj) {   
    var dlg = getEsrbAlertDialog('Alert', dialogMsg, callBack, obj);   
       e.preventDefault();
    dlg.modal('show');
};