最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I scroll HTML textbox to the end? - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Feb 16, 2012 at 14:06 Bill Software EngineerBill Software Engineer 7,78224 gold badges104 silver badges191 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14

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/derekaug/JGqtA/

<input id="longBox" type="text" value="mycurrtext" size="30" 
       onfocus="this.value = this.value;" name="longBox"/>

I would suggest this, simply when the input fields get's the focus the content is "set" so you automatically jump to the end.

发布评论

评论列表(0)

  1. 暂无评论