jquery UI对话框多次打开

时间:2012-03-20 21:09:47

标签: jquery user-interface dialog load

我遇到的问题是我的jquery UI对话框多次加载:

click -> opens dialog(1 time) -> close dialog
click - > opens dialog(2 times) -> close dialog
click - > opens dialog(4 times) -> close dialog
click - > opens dialog(8 times) -> close dialog

这里描述的正是:Why does my modal jQuery dialog open multiple times?

我遵循为该人工作的解决方案,但它对我不起作用。适用于该人的解决方案是:

1)初始化函数外的对话框 2)仅在load()

成功回调时打开

正如您所看到的,我在以下代码中执行了这两项操作,但问题仍然存在。请帮忙: (顺便说一下,一般结构是我点击一个链接加载一个对话框。然后当单击该对话框中的Register按钮时,我在其上加载另一个小确认对话框,其中一个OK按钮关闭两个对话框。)

$(document).ready(){
   var $registerDialogHandle = null;
    var $registerStatusDialogHandle = null;

    $registerDialogHandle = $('<div></div>').html("").dialog({
        autoOpen: false, modal: true,  width: 470, height: 552,
        buttons: {
            "Register": function () {
                if ($('#registerForm').validate().form()) {
                    $.ajax({
                        ...ajax settings...
                        success: function () {
                            openInDialog($registerStatusDialogHandle, "/Account/RegisterStatus");
                        }
                    });
                }
            }
        }
    });

    $registerStatusDialogHandle = $('<div></div>').html("").dialog({
        autoOpen: false, modal: true, width: 365, height: 165,
        buttons: {
            "OK": function () {
                $(this).dialog("close");
                $registerDialogHandle.dialog("close");
            }
        }
    });

    $('.registerLink').live("click", function () {
        openInDialog($registerDialogHandle, "/Account/Register?path=_RegisterPartial");
    });
} /*End of document.ready()*/

function openInDialog(dialog, target) {
    var $url = target;
    var $dialog = dialog;
    $dialog.empty();
    $dialog.dialog("option", "position", "center").load($url, function () {
         $dialog.dialog("open");
    });
}

1 个答案:

答案 0 :(得分:1)

如果我将.remove()来电更改为.hide()来电,似乎可以正常工作:

http://jsfiddle.net/jtbowden/s6SxE/