显示/隐藏div
我在vs 2005上使用asp.net ajax控件工具包1.0。我使用的是collapseablePanel和AlwaysVisibleControlExtender控件。当我使用这些时,我注意到我的面板在隐藏之前闪烁了几秒钟。显示/隐藏div
为了避免这种情况,我决定把它放在一个div中,使它隐藏起来。 我想在使用控件时显示它。
以下是我有:
<div id="menuContent" style="display:none">
<asp:Panel ID="pnlAddNewContent" runat="server" Width="300px">
....//the panel stuff here
</asp>
</div>
,并在标题中的JavaScript是这样的:
function showdiv() {
if (document.getElementbyId) {
document.getElementbyId('menuContent').style.visibility = 'visible';
}
}
(其对IE 6的我不关心的兼容性)
and body onload = onLoad =“showdiv();”
它正确隐藏负载,但我不能让它再次显示。有没有人有解决方案?
基本上不得不使用可见性隐藏和可见的属性,因为这些工作最好的a collapsePanel
您试图通过设置可见性来显示它,但是您使用显示屏隐藏了它。
实际上,你想是这样的:
的document.getElementById( 'menuContent')的style.display = '块'。
谢谢,我做到了,但使用隐藏和可见使用可视性。 您的人没有按照我希望它实现的方式在collapsePanel上正常工作。 – waqasahmed 2009-05-28 14:16:50
很高兴你把它分类。我建议将显示样式覆盖在可见的位置,因为显示会从可见的页面中移除内容,但仍占用页面上的空间,这可能会导致页面出现大的空白区域,将(或应该)使所有事情都能够取代它,这是更为常见的方法。 – 2009-06-01 13:30:24
也许这是你在找什么
JavaScript函数:
function showHide(descriptor)
{
var layer = document.getElementById(descriptor);
if (layer != null) {
if (layer.style.display != 'none') {
layer.style.display = 'none'; //hide layer
} else {
layer.style.display = 'block';//show layer
}
}
}
HTML:
<a href="javascript:showHide('divInfo');"><img id="imgInfo" src="info.gif" border="0" /></a>
<div style="display: none;" id="divInfo">some info</div>
nb改变可见性保留了渲染后的布局空间,改变了显示器会改变渲染后的布局(例如display:none会有效地折叠该元素) – annakata 2009-05-28 12:03:36
谢谢annakata,这是有用的建议..它为我解决了它 – waqasahmed 2009-05-28 14:14:50