简体   繁体   English

使用JavaScript控制文本框/溢出滚动

[英]Controlling textbox/overflow scrolling using javascript

I am trying to build a web console application at the moment. 我目前正在尝试构建Web控制台应用程序。 I have coded all the most major parts of the app, but I still need a way to display the text appropriately once I have brought it into the browser. 我已经对应用程序的所有最主要部分进行了编码,但是将文本带入浏览器后,我仍然需要一种适当显示文本的方法。 There will be more text than the box should be displaying at any one time, so there obviously needs to be some sort of scroll. 文本将比框一次显示的文本多得多,因此显然需要进行某种滚动。 A textarea would look right, as would a normal div which had overflow set to auto or scroll, however I NEED to be able to ensure that the box stays scrolled to the bottom, so that the most recent output is always being displayed. 一个textarea看起来正确,正常的div溢出设置为auto或滚动也可以,但是我需要确保框保持滚动到底部,以便始终显示最新的输出。 I don't see any DOM methods for a textbox or textarea that allow control of scroll position. 我没有看到用于控制滚动位置的文本框或文本区域的任何DOM方法。 Are there such things? 有这样的事吗? Is there any custom textbox type webapp that allows this sort of control? 是否有允许这种控制的自定义文本框类型的webapp?

This snippet shows how you can scroll a textarea to a specific line in a cross-browser way. 此代码段显示了如何跨浏览器将文本区域滚动到特定行。 Just scrolling to the bottom should be even easier: 滚动到底部应该更容易:

http://features.sheep.art.pl/AutoscrolledTextarea http://features.sheep.art.pl/AutoscrolledTextarea

Ah, little more searching gives this: Dynamically Scrolling a Textarea . 嗯,再进行一些搜索即可得出: 动态滚动Textarea Helpful! 有帮助! I think that should do it. 我认为应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM