js实现将div等滚动条(scrollbar)保持在最底部的方法

luoyjx · 2016-06-17 11:45 · 177次阅读

<style type="text/css">
.cdiv{
    background-color: white;
    height: 100px;
    width: 380px;
    padding-left: 0;
    overflow-y: scroll;
    position: relative;
    word-wrap: break-word;
    overflow-x: auto;
    text-align:left;
    }            
</style>
<div id="divmsg" class="cdiv"></div>
<input id="test" type="button" value="测试" />
<script type="text/javascript">
    var test = document.getElementById("test");
    var div = document.getElementById("divmsg");
    test.onclick = function () {
        div.innerHTML = div.innerHTML+"js实现将div等滚动条(scrollbar)保持在最底部的方法.--By <a href=\'https://blog.gaoqixhb.com\' target=\'_blank\'>blog.gaoqixhb.com</a>.<br/><br/>";
        div.scrollTop = div.scrollHeight;
    }
</script>

暂无评论

登录后可以进行评论。没有账号?马上注册