对话框隐藏()和显示()——Jquery?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17358622/
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-08-26 18:53:07  来源:igfitidea点击:

Dialog box hide() and show() -- Jquery?

jqueryjquery-ui-dialogjquery-dialog

提问by tíń?

Iam using 3 dialogs in my page for 3 diff purpose.

我在我的页面中使用 3 个对话框用于 3 个差异目的。

Iam creating dialog as

我正在创建对话框作为

  $(".dialog").dialog({
        height: 238,
        width: 465,
        resizable: false,
        title: "Edit"
    });

After my action done on dialog iam closing dialog as

在我对对话框完成操作后,我关闭对话框为

   $(".ui-dialog").hide();

When i hide this way dialog is not getting opening for 2nd time, So tried showing dialog starting of function like

当我以这种方式隐藏对话框时,第二次没有打开,所以尝试显示对话框启动功能,如

  $(".ui-dialog").show();

My problem started here....

我的问题从这里开始......

When i show dialog, Dialogs are getting opened multiple times, STill the first openined dialog is getting Overlapped wth the second dialog,

当我显示对话框时,对话框被多次打开,但第一个打开的对话框与第二个对话框重叠,

Is there any proper way to hide and Show dialog without overlapping or in clean way.

是否有任何正确的方法可以在不重叠或干净的情况下隐藏和显示对话框。

回答by Arun P Johny

You need to use the close(hide) and open(show) functions provided by the widget

您需要使用小部件提供的关闭(隐藏)和打开(显示)功能

$(".ui-dialog").dialog('close');
$(".ui-dialog").dialog('open');

回答by Tony Brix

If you just want to hide/show a dialog without closing it you can use

如果您只想隐藏/显示对话框而不关闭它,您可以使用

$(".dialog").parent().hide()
$(".dialog").parent().show()

回答by Harun ERGUL

To show/hidethe dialog we need to use open/closemethods

显示/隐藏对话框,我们需要使用打开/关闭方法

//To close the dialog use 'close' method.
//It will hide the dialog. Your html and data still exist in the DOM  
$("#my_dialog_id").dialog('close');   

//Show closed dialog again if it is still exists and not destroyed the
$("#my_dialog_id").dialog('open');

//This method totally destroy your dialog. Element will be returned to pre-init state
$("#my_dialog_id").dialog('destroy');

//To check if the dialog is open or not 
var isOpen = $( "#my_dialog_id" ).dialog( "isOpen" );