使用 javascript 使面板可见
我有一个面板,其属性 Visible 设置为 False
<asp:Panel ID="pnlUpload" runat="server" Visible="False" />
,我尝试使用 javascript 作为下面的代码使其可见
document.getElementById('<%= Panel1.ClientID %>').style.visibility = 'visible';
,但它不起作用,有什么想法吗?
I have a Panel with property, Visible set to False
<asp:Panel ID="pnlUpload" runat="server" Visible="False" />
and i try to make it visible using javascript as code below
document.getElementById('<%= Panel1.ClientID %>').style.visibility = 'visible';
but it's not working, any idea guys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
设置 Visible="false" 会使面板不在生成的 HTML 中呈现。如果你想让它在客户端显示/隐藏,你需要使它 Visible="true" 并使用 CSS 类/在具有“display”属性的样式属性中,其值为“block”或“none”必需的。
Setting Visible="false" makes the panel not to render in the generated HTML. If you want to make it show/hide in the client side, you need to make it Visible="true" and use a CSS class/in the style attribute having "display" property with the value "block" or "none" as required.
我以零 ASP 经验来回答这个问题,但有很多 JS/HTML/CSS 经验,所以如果我完全错了,请耐心等待......
我会说
Visible="False"
标签不是相当于 CSSstyle="visibility:hidden;"
因此 JS 调用不会产生任何效果。I am answering this with zero ASP experience but a lot of JS/HTML/CSS experience so bear with me if I am completely wrong...
I would say that the
Visible="False"
tag is not equivalent to the CSSstyle="visibility:hidden;"
therefore that JS call will have no effect.为了显示 asp 控件,您需要使用属性
示例:
正如上一篇文章中提到的属性
导致不渲染控件。
为了通过 Javascript 访问隐藏控件,您只需输入:
In order to display asp controls you need to use the property
Example:
As mentioned in a previous post the attribute
leads to not rendering the control.
In order to access the hidden control via Javascript you simply type:
我尝试了 .style.visibility = 'visible' 和visible="true" 和 .style.display = 'block'
和 .style.display = 'inline' 所有这些都不起作用。
但如果你写 .style.display = 'none' 它就可以工作。
任何人都知道解决方案
请告诉我
谢谢
I tried .style.visibility = 'visible' and visible="true" and .style.display = 'block'
and .style.display = 'inline' all those thing does not work.
but if you write .style.display = 'none' it work.
any body know the solution
Please let me know
Thanks
我的回答几乎是零 ASP 经验,例如 Flash84x :-)
似乎在 asp 中,当您设置“Visibile=false”时,不会创建面板。
如果您想使用自定义 JavaScript 而不是 .NET 工具来显示、隐藏面板,您应该直接在标签中应用样式,如下所示:
color:#FFFFFF;宽度:200;身高:200;
边框:实心1;填充:10">
......
然后它会在 html 中呈现类似这样的东西
:
背景颜色:#CC9999;颜色:#FFFFFF;宽度:200;
身高:200;边框:实心1;填充:10">
.....
当然相应的javascript是:
I answering with almost zero ASP experience, like Flash84x :-)
It seems that in asp, when you set "Visibile=false", the panel is not created.
And if you would like to use custom JavaScript and not the .NET facility to display, hide a panel you should apply a style directly in the tag like this:
color:#FFFFFF; width:200; height:200;
border:solid 1; padding:10">
.....
And then it will rendere somthing like this in html
:
background-color:#CC9999; color:#FFFFFF; width:200;
height:200; border:solid 1; padding:10">
.....
And of course the corresponding javascript would be:
请将您的面板放在 div 中
更改样式
并使用以下方式javascript
Please put your panel in a div
and change the style using the following way
javascript
不要使用可见性使用这个..
don't use visibility use this..