获得焦点时如何移动文本框视口? [英] How to move the textbox viewport when gaining focus?

查看:67
本文介绍了获得焦点时如何移动文本框视口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,可能包含大于文本框大小的字符串。当我输入时,文本框viewport总是移动以显示我输入的最后一个字符(例如,当你在SO问题中写一个非常大的标题时)。
a

I have a textbox that may contain strings larger than the textbox size. When I'm typing, the textbox "viewport" always moves to show the last character I typed (for example when you write a very large title in a SO question). a

问题是如果texbox失去焦点,当它再次聚焦时,视口总是设置在文本的开头,我想要它最后。

The problem is that if the texbox loses focus, when it is focused again the viewport always is set at the start of the text, and I want it at the end.

我尝试以编程方式将插入符号移动到文本的末尾并且它可以工作,但视口仍然在文本的开头,因此用户仍然必须按任意键才能将视口移动到文本末尾。

I tried moving the caret programatically to the end of the text and it works, but the viewport is still at the beginning of the text, so the user still has to press any key to move the viewport to the end of the text.

示例

这是失去焦点之前的文本框:

This is the textbox before losing focus:

替代文字http://img35.imageshack.us/img35/6697/10437837.jpg

此后焦点丢失了:

alt text http://img11.imageshack.us/img11/1390/33816597.jpg

我希望当txtbox再次获得焦点时,视口是像在...中设置第一张图片。

I'd like that when the txtbox gains focus again the viewport is set like in the first image.

可以这样做吗?

推荐答案

Sry ,但我不认为这是可能的。至少不是以干净和浏览器一致的方式。

Sry, but I don't think it's possible. At least not in clean and browser-consistent way.

这篇关于获得焦点时如何移动文本框视口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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