单击按钮关闭对话框 - JQuery UI

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

close dialog by clicking button - JQuery UI

jqueryjquery-ui

提问by roev

I try to create a button that closes "dialog" window in JQuery UI.

我尝试在 JQuery UI 中创建一个关闭“对话框”窗口的按钮。

To open the dialog i'm using this code:

要打开对话框,我正在使用此代码:

$(".show .edit_site").click(function (){
    rel = $(this).attr("rel");

    $("#dialog_edit").dialog({
            modal: true,
            open: function () {
                $(this).load("<?= site_url()?>/sites/show_update?id="+rel+"&mode=popup");
            },
            close: function() {
                //some code
            },
            height: 370,
            width: 900,
            title: 'Some title'
     });
}); 

The dialog opened and everything is fine. But now the question is how do I close the dialog by clicking on the button that is inside the dialog?

对话框打开,一切正常。但现在的问题是如何通过单击对话框内的按钮关闭对话框?

enter image description hereThank you all and sorry for my terrible English :)

在此处输入图片说明谢谢大家,为我糟糕的英语感到抱歉:)



I tried every possible solution, this the only one who works for me:

我尝试了所有可能的解决方案,这是唯一为我工作的解决方案:

function close_dialog()
{
    //Close jQuery UI dialog 

    $(".ui-dialog").hide();
    $(".ui-widget-overlay").hide();
}

回答by bfavaretto

It's simple, just add the button as part of the dialog's options:

很简单,只需将按钮添加为对话框选项的一部分:

$("#dialog_edit").dialog({
    modal: true,
    open: function () {
        $(this).load("<?= site_url()?>/sites/show_update?id="+rel+"&mode=popup");
    },
    height: 370,
    width: 900,
    title: 'Some title',
    buttons: {
        'button text' : function() {
            $(this).dialog('close');
        }
    }
});

回答by Engineer

You can use 'close'method:

您可以使用“关闭”方法:

$("#dialog_edit").on('click', '#closeButtonId', function(){
     $(this).closest("#dialog_edit").dialog('close');
});

回答by Raj Kumar

I tried the below code and it worked

我尝试了下面的代码并且它有效

 $('#btnClose').click(function () {
     window.parent.jQuery('#msgbox').dialog('close');
 });