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

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

问题描述

我有一个文本区域,它在发送用户输入时动态重新加载.它每隔几秒钟刷新一次.当此 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天全站免登陆