jQuery 使用jquery创建对话框时,如何隐藏对话框div?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2513051/
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
When creating a dialog with jquery, how do I hide the dialog div?
提问by stormist
I am creating a dialog like in this page:
我正在创建一个像这个页面中的对话框:
http://jqueryui.com/demos/dialog/#modal-confirmation
http://jqueryui.com/demos/dialog/#modal-confirmation
(click view source)
(点击查看源码)
on the bottom is the div that gets placed in the dialog. The dialog works perfect when called by the javascript but the dialog is apparent at the bottom of the page when it loads. (minus all the styling that gets applied when it is called by the javascript function)
底部是放置在对话框中的 div。该对话框在被 javascript 调用时工作完美,但加载时该对话框在页面底部很明显。(减去 javascript 函数调用时应用的所有样式)
How can I hide the div and still allow the dialog to use it? I have tried setting style="visibility:hidden" but that prevents it from being shown when called by the javascript.
如何隐藏 div 并仍然允许对话框使用它?我试过设置 style="visibility:hidden" 但这会阻止它在被 javascript 调用时显示。
回答by R0MANARMY
This may be a stupid question, but instead of "visibility:hidden"
have you tried "display:none;"
? I had to solve the same problem for a project I'm working on and I'm reasonably sure display:none worked.
这可能是一个愚蠢的问题,但"visibility:hidden"
你有没有尝试过"display:none;"
?我必须为我正在处理的项目解决同样的问题,我有理由确定 display:none 工作。
You can also use the
您还可以使用
$(foo).dialog({ autoOpen: false });
option to "initialize" the dialog (thus hiding it and all that good stuff). The only catch is, you'll probably see the dialog "flicker" as the page loads but before jQuery has a chance to hide it.
“初始化”对话框的选项(从而隐藏它和所有好东西)。唯一的问题是,您可能会在页面加载时看到对话框“闪烁”,但在 jQuery 有机会隐藏它之前。
回答by Muhammad Awais
You can try the following it works for me:
您可以尝试以下对我有用的方法:
$("#form-dialog").dialog("close");