删除 jQuery UI 对话框小部件上的关闭按钮的最佳方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3566765/
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
Best way to remove the close button on jQuery UI dialog box widget?
提问by Alex KeySmith
What's the best way to remove the close button on the jQuery UI dialog box?
删除 jQuery UI 对话框上的关闭按钮的最佳方法是什么?
I do not wish people to be able to close the dialog box.
我不希望人们能够关闭对话框。
I'm covering it on the code angle by handling:
我通过处理在代码角度覆盖它:
closeOnEscape: false,
beforeclose: function (event, ui) { return false; }
I'm trying not to need to write script to grap the class / id of the close button and then hide it manually. And I'd rather not change the CSS manually either, as the dialog box may have situations where it needs the close button.
我试图不需要编写脚本来抓取关闭按钮的类/ID,然后手动隐藏它。而且我也不想手动更改 CSS,因为对话框可能会出现需要关闭按钮的情况。
I'd prefer to do it the dialog config somehow, but either I can't figure out how to do it or the dialog box doesn't allow for it at all.
我更喜欢以某种方式执行对话框配置,但要么我不知道该怎么做,要么对话框根本不允许这样做。
Any suggestions on how to configure the dialog box?
关于如何配置对话框的任何建议?
回答by Alex KeySmith
I found this to be a good solution
我发现这是一个很好的解决方案
$("#myDialogID").dialog({
closeOnEscape: false,
beforeClose: function (event, ui) { return false; },
dialogClass: "noclose"
});
Not altering the existing styles, instead adding a new bit:
不改变现有样式,而是添加新样式:
.noclose .ui-dialog-titlebar-close
{
display:none;
}
Adding the class ended up being quite an elegant method, as i'm "classing" the dialog as one that cannot be closed.
添加类最终成为一种非常优雅的方法,因为我将对话框“分类”为无法关闭的对话框。
回答by Chirag Thakar
I found another solution, works for me:
我找到了另一个解决方案,对我有用:
$("#divID").dialog({
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
});