html textarea 自动在底部滚动的实现方法------终于搞定你

来源:互联网 发布:宾得wifi软件 编辑:程序博客网 时间:2024/04/30 12:58

       之前在BCB中也是一样, 多行文本框的滚动, 很不人性化,  看不到滚动效果, 后来我用特殊方法解决了。 

       如今的html textarea也遇到同样问题, 摸索良久, 终于搞定大笑, 如下:

<html><body><textarea rows="10" cols="20" id="my"></textarea><button onClick="test()">test</button><script>var i = 1;function test(){var obj = document.getElementById("my");    obj.value += i + "\n";    i++;obj.scrollTop = obj.scrollHeight; // good}</script></body></html>
       经测试, 靠谱。





0 0