javascript JQuery UI 多对话框问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8861853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:48:41  来源:igfitidea点击:

JQuery UI Multiple Dialog Issue

javascriptjqueryjquery-ui

提问by AliMan

I have functionality where I dynamically create Dialog. Some time I require Modal or Confirm Dialog

我有动态创建对话框的功能。有时我需要模态或确认对话框

So I created to Function

所以我创建了函数

function createDialogWithOutClose()
{
    jQuery('#divPopup').dialog('destroy');

    var dialog = jQuery('#divPopup').dialog({
        autoOpen: false,
        height: 450,
        width: 650,
        modal: true,
        open: function(event, ui){
            jQuery('body').css('overflow','hidden');
        }

    });

    jQuery('#divPopup').dialog('open');
}

and

function createConfirmDialog(url,params)
{
    jQuery('#divPopup').dialog('destroy');

    var dialog = jQuery('#divPopup').dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        show: "blind",
        hide: "explode",
        open: function(event, ui){
            jQuery('body').css('overflow','hidden');
        },
        buttons: {
            Ok: function() {
                jQuery( this ).dialog( "close" );
                jQuery.ajax({
                    type: "POST",
                    url: url,
                    data: params
                });
            },
            Cancel: function() {
                jQuery( this ).dialog( "close" );
            }
        }

    });

    jQuery('#divPopup').dialog('open');

}

Problem here is when I give call to this function, It opens previously opened Dialog.

这里的问题是当我调用这个函数时,它会打开以前打开的对话框。

I guess previous instance is not get removed.It doesnt dynamically create Dialog

我猜以前的实例不会被删除。它不会动态创建对话框

Any solution??

有什么解决办法吗??

回答by Adnan Iqbal

Simply use a flag to check dialog state (close/open)

只需使用一个标志来检查对话框状态(关闭/打开)

var Open = false;
$('button').click(function () {
    if (!Open) {
        Open = true;
        $(newDiv).dialog({
            close: function (event, ui) {
                Open = false;
            }
        });

    } else {
        alert("Close opened dialog first");
    }
});