尝试过visibility:hidden,可以使用document.getElementById('xxx').clientWidth获得其实际宽度,但是定义为display='none'的层使用document.getElementById('xxx').clientWidth获取的宽度却是0,如何获取一个定义为display='none'属性的层的实际宽度呢?忘赐教啊!小生谢过了。

解决方案 »

  1.   

    popDivWidth = divObj.offsetWidth != null ? parseInt(sObj.offsetWidth) : 0; popDivHeight = divObj.offsetHeight != null ? parseInt(divObj.offsetHeight) : 0;
      

  2.   

    考虑visibility,占据位置
    display=“none”不占据位置
      

  3.   

    visibility:hidden + position:absolute
      

  4.   


    <div id="layer2" style="height:30px;display:none">
    ddd
    </div>
    </body>
    <script type="text/javascript">
    var obj=document.getElementById("layer2"),h
    if(obj.currentStyle)
        h=obj.currentStyle.height;
    else
        h=window.getComputedStyle(obj,null).getPropertyValue("height");
    alert(h);
    </script>
      

  5.   

    我也遇见过这个问题,我是刚开始时设置display=block,然后在初始化函数中先获得该div的宽度之后,再设置display=none