可以利用window.body.scrollHeight和window.body.clientHeight的高度差别来比较,如果前者大于后者,则有滚动条,反之没有。这是IE和Opera中情况,firefox则比较offsetScroll和clientHeight

解决方案 »

  1.   

    window.body.scrollHeight?  是 DIV的 scrollHeight?
      

  2.   

    反正就是这个思路,应用到div也是一样的,你不妨试一下下面的代码,就知道思路在哪了
    <html>
    <head>
    <title></title>
    <style type="Text/css">
    #divTest{
    width:200px;
    height:200px;
    overflow:auto;
    background-color:#DFDFDF;
    }
    </style>
    <script type="text/javascript">
    window.onload=function(){
    var obj=document.getElementById("divTest");
    alert("clientHeight:" + obj.clientHeight);
    alert("scrollHeight:" + obj.scrollHeight);
    alert("offsetHeight:" + obj.offsetHeight);
    }
    </script>
    </head>
    <body>
    <div id="divTest">
    sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>sdfs<br/>
    </div>
    </body>
    </html>
      

  3.   

    上面的的结果并非完全正确。
    当一个DIV嵌在一个Table中的某个TD里面,而且外面的Table设置100%,上述操作失效