【问题标题】:Page Refreshes before jQuery dialog is closed在 jQuery 对话框关闭之前页面刷新
【发布时间】:2012-02-03 13:28:27
【问题描述】:

我创建了一个函数,用我自己的函数替换了window.alert 函数,该函数利用了jquery.dialog。问题是在某些函数中我调用该函数并在之后重新加载页面。它应该在用户单击“确定”时刷新它,但在我单击“确定”之前它会自行重新加载页面。

以下是函数中调用顺序的示例:

function UpdateCertSucccess(result) {
customAlert("Hello World");
window.location.href = "./SomePage.aspx";
}

这是我定义的customAlert()

function customAlert(message) {
if (!isOpen) {
    $('#error-message-dialog').dialog({
        autoOpen: false, bgiframe: true, position: ['center', 100], modal: true, zIndex: '6000', title: 'R+L Carriers Message', width: 475, height: 250,
        buttons: {
            "OK": function () {
                $(this).dialog("close");
                isOpen = false;

            }
        }
    });
    var elements = message.split("|");
    $('#spMessage').text(elements[0]);
    $('#spCode').text(elements[1]);
    $('#spTime').text(elements[2]);
    $('#spServer').text(elements[3]);
    $('#error-message-dialog').dialog('open');
    isOpen = true;

       }
else {
    $('#spMessage').append("<br /><br />");
    $('#spMessage').append(message);
}
return false;

};

在我关闭对话框之前可能会导致页面重新加载,我该如何解决? 谢谢!

【问题讨论】:

  • 一个问题是 real 警报实际上会在显示脚本时阻止脚本执行。像您这样的对话框无法做到这一点。您可以做的是通过在整个窗口上放置透明的&lt;div&gt; 或其他内容来阻止与底层页面的交互,这样用户事件就无法通过。

标签: javascript jquery jquery-ui-dialog


【解决方案1】:

删除'window.location.href = "./SomePage.aspx";'从 'UpdateCertSuccccess()' 函数中,并在确定单击后将其放在函数调用中(确定单击关闭对话框的回调函数)

【讨论】:

    【解决方案2】:

    只有浏览器弹出窗口(警报、确认...)可以暂停功能的执行。你自己不能达到同样的效果,所以你需要改进你的代码,添加一个“onclose”回调选项或其他东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      • 2019-01-26
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      相关资源
      最近更新 更多