注重与插入符号在textarea的Andr​​oid浏览器文本之后 [英] Focus textarea with caret after text in Android browser

查看:146
本文介绍了注重与插入符号在textarea的Andr​​oid浏览器文本之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个简单的Web应用程序在Android浏览器中查看鸣叫。
我用这code集中插入符的当前文本之后:

I am currently writing a simple webapp to view tweets in the Android browser. I am using this code to focus the caret after the current text:

var oldContent = document.tweetBox.tweet.value;
document.tweetBox.tweet.value = '';
document.tweetBox.tweet.focus();
document.tweetBox.tweet.value = oldContent + to;

这code完美的作品在Chrome中,生津,歌剧,火狐恩野生动物园。结果
最奇怪的是,光标开始闪烁到文本之后,如果我用我的硬件键盘,但我进入启动JS上述被执行之前,我在那里键入的文本。结果
如果我使用软键盘文本进入开始在textarea的开始。

This code works flawlessly in Chrome, Fluid, Opera, Firefox en Safari.
The weirdest part is that the cursor starts blinking AFTER the 'to' text if I use my hardware keyboard but the text that I enter starts where I was typing before the JS above was executed.
If I use the soft keyboard the text entering starts at the start of the textarea.

P.S的JavaScript是追随者建议的一部分,所以如果你开始输入@gn它将在一个单独的分区建议@gnur_nl,当你preSS输入选择此项。

p.s The javascript is part of a suggestion for followers, so if you start typing @gn it will suggest @gnur_nl in a seperate div and when you press enter this entry is chosen.

更新:此行为似乎是一个浏览器错误,的 bug报告已经提交

Update: This behaviour seems to be the result of a browser bug, a bug report has been filed.

推荐答案

听起来像是一个浏览器的bug。尝试手动设置插入符的位置:

Sounds like a browser bug. Try setting the caret position manually:

var textArea = document.tweetBox.tweet, oldContent = textArea.value;
textArea.value = oldContent + to;
textArea.focus();
textArea.selectionStart = textArea.selectionEnd = textArea.value.length;

这篇关于注重与插入符号在textarea的Andr​​oid浏览器文本之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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