将光标放在文本输入值的末尾

将光标放在文本输入值的末尾

问题描述:

所以,目前我有一个文本输入字段,其值也是自动聚焦的。

So, currently I have a text-input-field with a value that is also autofocused.

在页面加载时,值被选中/突出显示。是否有一种方法,我可以把光标放在值文本的结尾,而不是在javascript或CSS中突出显示?

On page load, the value is selected / highlighted. Is there a way I can put the cursor at the end of the value text instead of highlighting it in javascript or CSS?

这里是一个js fiddle哪里自动聚焦文本的值已突出显示: http://jsfiddle.net/TaGL5/

Here is a js fiddle where the autofocused text's value is highlighted: http://jsfiddle.net/TaGL5/

此处是HTML代码:< input type =textvalue =value textautofocus />

Here is the HTML code: <input type="text" value="value text" autofocus />

这适用于我

<input type="text" autofocus value="value text" onfocus="this.value = this.value;"/>