function show(val)
    {
    if(document.getElementById(val).style.display == 'none')
    document.getElementById(val).style.display ='block';
    else
    document.getElementById(val).style.display = 'none';
    }
请各位大虾帮帮忙啊~~
我在IE8下面测试是OK的,但是在火狐下没效果,在网上找了很多地方,
都说把display=‘block’改为display=''就ok,可是我试了不行,请问还有其他办法吗??

解决方案 »

  1.   

    $("#content2 , #content3").css("display" , "none");
    $("#content1").css("display" , "");
      

  2.   

    <html>
    <head>
    <title>层</title>
    <script type="text/javascript">
      function show(val)
    {
    if (document.getElementById(val).style.display == 'none')
    { document.getElementById(val).style.display = 'block';
    }
    else
    { document.getElementById(val).style.display = 'none';
    }
    }  
    </script>
    </head>
    <body>
    <input type='text' id='tx1' style="display:none">
    </body>
    <input type="button" onclick="show('tx1')" value="点我">
    </html>火狐下 没问题
      

  3.   

    你代码哪里有问题吧,display block没有不兼容的说法
      

  4.   

    --->源码[align=left][align=left][align=left] <a href="javascript:void(0)" onclick="show('myor')">我的OpenRice</a>
     <div class="bottom_myor" id="myor" style="display:none">
                  <ul>
                    <li>
                      <a href="{Context:BuildUrl('gourmet','reviews')}?userid={CurrentUser/User/UserId}">我的食评</a>
                    </li>
                    <li>
                      <a href="{Context:BuildUrl('gourmet','briefreviews')}?userid={CurrentUser/User/UserId}">我的短评</a>
                    </li>
                    <li>
                      <a href="{Context:BuildUrl('gourmet','photos')}?userid={CurrentUser/User/UserId}">我的相片</a>
                    </li>
                    <li>
                      <a href="{Context:BuildUrl('gourmet','bookrestaurant')}?userid={CurrentUser/User/UserId}">开饭行踪</a>
                    </li>
                    <li>
                      <a href="{Context:BuildUrl('gourmet','bbs')}?userid={CurrentUser/User/UserId}">我的留言</a>
                    </li>
                  </ul>
                </div>
      

  5.   

    就是很简单的控制层显示和隐藏哦~~~很多人都说火狐不支持display='block'呢
      

  6.   

    <html><head> 
    <script type="text/javascript">
     
    function show(val)
      {
      if(document.getElementById(val).style.display == 'none')
      document.getElementById(val).style.display ='block';
      else
      document.getElementById(val).style.display = 'none';
      }
    </script>
    </head><body>
    <p id='val' onclick="show(this.id)">If you click on me, I will disappear.</p>
    <input onclick="show('val')" type='button' value='show the p' />
    </body></html> 
    我的FF3.6.18  没有问题
      

  7.   

    我也很奇怪啊。。可是问题确实存在。。disply 会被其他属性所影响吗??比如poistion??
      

  8.   

    记得在元素上显式加上
    <p style='display:block'></p>
      

  9.   

     我的那段 没有position,你试一下,如果有问题,估计是你的FF有问题
      

  10.   

    我把这段代码copy出来了在ff可以实现隐藏关闭那应该是其他css引起的可是我用了很多样式啊。。这部分必须和css结合来做的实现层的显示和隐藏。。还有其他方法吗
      

  11.   

    firefox 3.6,ie8 一切正常。<script type="text/javascript">        function toggle()
            {
                var p = document.getElementById("test");
                p.style.display = p.style.display === "block" ? "none" : "block";
            }    </script>    <p id="test" style="display:none">p</p>
        <input type="button" value="test" onclick="toggle()" />
      

  12.   

    问题解决了,是css的问题,火狐是支持display=block 的,直接在层里面写css: style="display:none",火狐是不支持的,在JS里面给层赋值 Avl.style.display = "none";就ok了
    修改后的code:window.onload= function show()
        {
          var Avl = document.getElementById("myor");
          Avl.style.display = "none";
          document.getElementById("bottom").onclick = function(){
          Avl.style.display = Avl.style.display == "block" ? "none" : "block";}
        }
    PS:还是谢谢各位啊~~问题出在对css了解不透彻,还有不懂IE和火狐之间性能的不同~~
      

  13.   

    很奇怪,我最近也遇到一個問題,如果將原來隱藏的樣式寫在非標籤上,也就是非<div id="xx" style="display:none">這種方式,用style.display=""也是無效,只能用block,但是如果換回樣式寫在標籤上則兩種寫法均可。感覺很奇怪~~~
      

  14.   

    我也遇到这个问题,在IE中<span style="dispaly='none'">能隐藏,在ff中却不能!