查詢了一下相關的資料,Div沒有自動滾動的屬性,只能模擬鼠標的滾動來現實想要的效果。
關鍵的部分部分在這裡:div.scrollTop = div.scrollHeight;
下面是具體實現的精簡代碼:
復制代碼 代碼如下:
<html>
<body>
<div id="divDetail" style="overFlow-y:scroll; width:250px;height: 200px;">
<table style="border:1px solid; ">
<tr><td>id</td><td>name</td><td>age</td><td>memo</td></tr>
<tr><td>000001</td><td>name1</td><td>24</td><td>memomemomemomemomemo</td></tr>
<tr><td>000002</td><td>name2</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000003</td><td>name3</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000004</td><td>name4</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000005</td><td>name5</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000002</td><td>name2</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000003</td><td>name3</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000004</td><td>name4</td><td>23</td><td>memomemomemomemomemo</td></tr>
<tr><td>000005</td><td>name5</td><td>23</td><td>memomemomemomemomemo</td></tr>
</table>
</div>
</body>
<script type="text/javascript" defer>
var div = document.getElementById('divDetail');
div.scrollTop = div.scrollHeight;
//alert(div.scrollTop);
</script>
</html>
其實,實現是很簡單的但是一般很少有這種需求,期間還是走了一些彎路。