简体   繁体   English

显示/隐藏div

[英]Showing/Hiding div

I am using asp.net ajax control toolkit 1.0 on vs 2005. I am using the collapseablePanel and AlwaysVisibleControlExtender control. 我在vs 2005上使用asp.net ajax控件工具包1.0。我正在使用可折叠面板和AlwaysVisibleControlExtender控件。 When I use these, I notice that it my panel flashes for a few seconds before it is hidden. 当我使用它们时,我注意到面板隐藏前会闪烁几秒钟。

To avoid this, I have decided to place it in a div to make it hidden. 为了避免这种情况,我决定将其放在div中以使其隐藏。 I want it shown when I use the control. 我希望在使用控件时显示它。

Here is what I have: 这是我所拥有的:

<div id="menuContent" style="display:none">

 <asp:Panel ID="pnlAddNewContent" runat="server" Width="300px">
   ....//the panel stuff here
 </asp>
</div>

and the javascript for this in the header is: 并且标头中的javascript是:

    function showdiv() { 
    if (document.getElementbyId) {
        document.getElementbyId('menuContent').style.visibility = 'visible'; 
    } 

    } 

(its for IE 6 for I don't care about compatability) (对于IE 6,我并不在乎兼容性)

and body onload=onLoad="showdiv();" 和正文onload = onLoad =“ showdiv();”

It correctly hides upon load, but I cannot get it to show again. 它在加载时正确隐藏,但是我无法再次显示它。 Does anyone have solutions? 有人有解决方案吗?

You are trying to show it by setting the visibility but you hid it using display. 您试图通过设置可见性来显示它,但使用显示隐藏了它。

You actually want something like this: 您实际上想要这样的东西:

document.getElementbyId('menuContent').style.display = 'block'; document.getElementbyId('menuContent')。style.display ='block';

Maybe this is what you're looking for 也许这就是您要寻找的

Javascript function: 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: HTML:

<a href="javascript:showHide('divInfo');"><img id="imgInfo" src="info.gif" border="0" /></a>
<div style="display: none;" id="divInfo">some info</div>

基本上必须使用“可见性”隐藏和可见属性,因为这些属性在崩溃面板上效果最佳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM