开发者

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

开发者 https://www.devze.com 2023-04-13 05:14 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Set Focus After Last Character in Text Box
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

精彩评论

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

关注公众号