开发者

How can I put focus on a field after the entered text? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Set Focus After Last Character in Text Box

I have a text field that has a default value in it. I would like to 开发者_JAVA技巧use jquery to focus on this field, but using focus() puts the cursor before the text that's already entered. How can I focus the cursor after the entered text?


You can set the caret position like this: http://jsfiddle.net/tSChT/.

var textbox = $("#textbox");

textbox.prop("selectionStart", textbox.val().length) // set caret to length (end)
       .focus();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜