How can I put focus on a field after the entered text? [duplicate]
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();
精彩评论