如何使用异步JQuery确认对话框作为同步?

时间:2012-04-23 13:05:37

标签: asynchronous callback jquery-ui-dialog confirm

我使用了一个简单的JavaScript确认函数,我的Asp.net项目中的所有页面都使用它,我想用jQuery确认对话框替换它。 我使用Apprise jQuery确认对话库。 但是jQuery的异步工作确认对话框会导致问题。 让我给你一些我项目的代码示例..

这是我以前的旧JavaScript确认功能

function confirmForOperation(message) {
    if (confirm(message) == true)
        return true;
    else
        return false;
}

这是我的新异步jQuery确认对话框功能

function confirmForOperation(message) {
    apprise(message, { 'verify': true, 'animate': true, 'textYes': 'Yes', 'textNo': 'No' },
    function (r) {
        if (r) {
            // User clicked YES..
            return true;
        }
        else {
            // User clicked NO..
            return false;
        }
    });
}

您可以让我使用以下功能

function confirmForOperation(message, callBack) {
    apprise(message, { 'verify': true, 'animate': true, 'textYes': 'Yes', 'textNo': 'No' },
    function (r) {
        if (r) {
            // User clicked YES..

            if ($.isFunction(callback)) {
                callback.apply();
            }
        }
        else {
            // User clicked NO..
            return false;
        }
    });
}

但是callBack机制对我不起作用,因为我使用这个确认对话框功能的区域(代码)之一如下:

<asp:Button ID="btnDelete" runat="server" CausesValidation="false" CommandName="Delete"
Text="<%$ Resources:BTNResource, BUTTON_DELETE_LABEL %>" OnClientClick="return confirmForOperation();" />

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我也是这样看,答案是否定的。在这里看到这个出色的解释:

Change the asynchronous jQuery Dialog to be synchronous?