设置了 overflow-y:scroll 的时候,获取实际的文档高度

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
     </head>
     <style type="text/css">
    div{width:200px;height:100px;border:1px solid gray;overflow-y:scroll;}
     </style>
    <script type="text/javascript">
    function getHeight(){
    var div=document.getElementsByTagName("div")[0];
    alert("文档高度: "+div.scrollHeight);
    // alert(div.scrollTop);
    // alert("div 高度:"+div.clientHeight);
    // alert(div.offsetHeight);



    }
    </script>
     <body>
      <div>
      <label>1</label><br/>
      <label>2</label><br/>
      <label>3</label><br/>
      <label>4</label><br/>
      <label>5</label><br/>
      <label>6</label><br/>
      <label>7</label><br/>
      <label>8</label><br/>
      <label>9</label><br/>
      <label>10</label><br/>
      <label>11</label><br/>
      <label>12</label><br/>
      <label>13</label><br/>
      </div>
      <input type="button" value="getHeight" onclick="getHeight();"/>
     </body>
    </html>