可以使用JavaScript将插入符号滚动到单个HTML文本字段内的视图中吗? [英] Possible to scroll caret into view inside a single HTML text field with JavaScript?
问题描述
了解 jQuery Caret插件后,我仍然看不到以下方法带有JavaScript的HTML(即input:type=text
控件)中的单行文本框:
Knowing the jQuery Caret plugin, I'm still seeing no way to do the following on a single line text box in HTML (i.e. the input:type=text
control) with JavaScript:
- 以编程方式将文本插入文本框
- 将插入符设置到末尾.
- 使插入符号可见(即滚动文本框内容)
- Programmatically inserting text into a text box
- Setting the caret to the end.
- Making the caret visible (i.e. scroll the text box content)
我知道该怎么做1.和2.,仅针对3..我发现没有办法.
I know how to do 1. and 2., just for 3. I have found no way of doing it.
说明一下:
我的问题是:
有没有办法可靠地将插入符号放在文本的末尾并滚动到视图中?
Is there any way to reliable put the caret at the end of the text and scroll it into the view?
(我可以考虑模拟按END
键或类似的操作,但是我不确定这是否是最佳选择).
(I can think of simulating pressing the END
key or something like that, but I'm unsure whether this would be the best option).
推荐答案
//hack将光标移到最后:
//hack to get cursor at end:
$(textboxselector).val($(textboxselector).val());
应首先注意重点:
$(textboxselector).val(newtext);
$(textboxselector).focus();
$(textboxselector).val($(textboxselector).val());
这篇关于可以使用JavaScript将插入符号滚动到单个HTML文本字段内的视图中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!