日期:2014-05-16 浏览次数:20509 次
<html>
    <head>
        <title></title>
        <script type="text/javascript">
            function getHeight(id){
                var obj = document.getElementById(id);
                obj.style.overflow = "scroll";
                alert(obj.scrollHeight);
                obj.style.overflow = "hidden";
                
            }
            
            window.onload = function () {
                 getHeight("dh");
                 alert(document.getElementById('ds').scrollHeight)
            }
        </script>
        <style type="text/css">
            .divHidden{
                width:100px;
                height:100px;
                overflow:hidden;
            }
            .divScroll{
                width:100px;
                height:100px;
                overflow:scroll;
            }
        </style>
    </head>
    <body>
        <div id="dh" class="divHidden">
            第一行
            dfsadfadf
            asdf
            sdf
            dsfsdfsadfadf
            asdf
            sdf
            dsfsd
            hasdgjoijgdsgdfsadfadf
            asdf
            sdf
            dsfsdfsadfadf
            asdf
            sdf
            dsfsd
            hasdgjoijgdsg
            最后一行
        </div>
        <input type="button" value="getHiddenHeight" onclick="getHeight('dh')" />
        
        </br>
        
        <div id="ds" class="divScroll">
            第一行
            dfsadfadf
            asdf
            sdffsadfadf
            asdf
            sdf
            dsfsd
            dsfsd
            hasdgjoijgdsgdfsadfadf
            asdf
            sdf
            dsfsdfsadfadf
            asdf
            sdf
            dsfsd
            hasdgjoijgdsg
            最后一行
        </div>
        <input type="button" value="getScrollHeight" onclick="alert(document.getElementById('ds').scrollHeight)" />
    </body>
</html>
            function getHeight(id){
                var obj = document.getElementById(id);
                obj.style.overflow = "scroll";
                setTimeout(function(){
                  alert(obj.scrollHeight);
                  obj.style.overflow = "hidden";
                }, 50);
                
            }