JavaScript - control.style.display = "none"; 和 control.style.display = "";?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4597078/
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
JavaScript - control.style.display = "none"; and control.style.display = "";?
提问by Johnrad
When I created a label I set it's display to none in the designer.
当我创建一个标签时,我在设计器中将它的显示设置为无。
<asp:Label ID="label1" runat="server" style="display:none;" Text="LABEL" asp:Label>
I use javascript to turn the label visible by:
我使用 javascript 将标签变为可见:
var lbl = document.getElementById('label1');
lbl.style.display="";
WHen I do this the space is created where the label would be on the form but the label itself doesn't show up. I have tried
当我这样做时,会在表单上标签所在的位置创建空间,但标签本身不显示。我努力了
lbl.style.display="inline";
lbl.style.display="block";
just to see if the label would show up. Still nothing though. Just the extra space where the label would be is created.
只是为了看看标签是否会出现。不过还是什么都没有。只是创建标签的额外空间。
回答by sjngm
You were saying
你是说
WHen I do this the space is created where the label would be on the form but the label itself doesn't show up. I have tried
当我这样做时,会在表单上标签所在的位置创建空间,但标签本身不显示。我努力了
That makes me believe that somewhere in your CSS you may have visibilityset to hidden. That normally covers the space of the element, but doesn't show it. The displaycontrols whether or not the space is preserved for the element.
这让我相信在你的 CSS 中你可能已经visibility将hidden. 这通常会覆盖元素的空间,但不会显示它。该display控制是否在空间保存的元素。
回答by Jonathan Wood
Are you certain you have the control ID correct? Unless you set ClientIDMode to Static, the actual control ID will probably be something much longer than the ID you specify. Check the control's ClientID property.
您确定控制 ID 正确吗?除非您将 ClientIDMode 设置为静态,否则实际控件 ID 可能会比您指定的 ID 长得多。检查控件的 ClientID 属性。

