我如何设置textarea滚动条到底部作为默认值? [英] How do I set textarea scroll bar to bottom as a default?

查看:707
本文介绍了我如何设置textarea滚动条到底部作为默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个textarea正在动态重新加载作为用户输入的发送。它每隔几秒刷新自己。当此文本区域中的文本量超出文本区域的大小时,会出现一个滚动条。然而,滚动条不是真正可用,因为如果你开始向下滚动,几秒钟后textarea刷新,并把滚动条右上方到顶部。我想将滚动条设置为默认显示最底部的文本。

I have a textarea that is being dynamically reloaded as user input is being sent in. It refreshes itself every couple seconds. When the amount of text in this textarea exceeds the size of the textarea, a scroll bar appears. However the scroll bar isn't really usable because if you start scrolling down, a couple seconds later the textarea refreshes and brings the scroll bar right back up to the top. I want to set the scroll bar to by default show the bottom most text. Anyone have an idea of how to do so?

推荐答案

很简单,在vanilla javascript:

pretty simple, in vanilla javascript:

var textarea = document.getElementById('textarea_id');
textarea.scrollTop = textarea.scrollHeight;

这篇关于我如何设置textarea滚动条到底部作为默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆