单击按钮关闭对话框 - 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
close dialog by clicking button - JQuery 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?
对话框打开,一切正常。但现在的问题是如何通过单击对话框内的按钮关闭对话框?
Thank 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
回答by Raj Kumar
I tried the below code and it worked
我尝试了下面的代码并且它有效
$('#btnClose').click(function () {
window.parent.jQuery('#msgbox').dialog('close');
});