如何滚动HTML文本框到最后? [英] How do I scroll HTML textbox to the end?

查看:276
本文介绍了如何滚动HTML文本框到最后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果HTML文本框的内容比文本框的宽度更长,则其中的一部分会被隐藏,您需要滚动文本框才能看到结尾。有没有办法在JS或CSS中将其滚动到最后?

>

以下是< input type =text/> 和宽度。

  var ta = document.getElementById('temp'); 
ta.scrollLeft = ta.scrollWidth;

我的小提琴更新以显示它。


$ b 身高



  var ta = document.getElementById('temp')您可以在元素上使用scrollHeight和scrollTop来执行此操作。 ; 
ta.scrollTop = ta.scrollHeight;

小提琴: http://jsfiddle.net/derekaug/JGqtA/


If the content of a HTML textbox is longer than the textbox width, part of it is hidden and you need to scroll the textbox to see the end. Is there anyway to scroll it in JS or CSS to the end?

解决方案

Width

Here's for an <input type="text" /> and width.

var ta = document.getElementById('temp');
ta.scrollLeft = ta.scrollWidth;

And my fiddle is updated to show this.

Here's my previous response with doing it for the height.

Height

You can use scrollHeight and scrollTop on an element to do this.

var ta = document.getElementById('temp');
ta.scrollTop = ta.scrollHeight;

Fiddle: http://jsfiddle.net/derekaug/JGqtA/

这篇关于如何滚动HTML文本框到最后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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