jQuery: How to focus on input text field such that the cursor is placed at the end of the text?
Consider the following example: (demo here)
HTML:
<input type="text" />
<div>Click here to set focus</div>
JS:
$(function开发者_StackOverflow中文版() {
$("input").val("Hello");
$("div").click(function() {
$("input").focus();
});
});
When the div
is clicked, the cursor positioned at the beginning of the text: |Hello
.
How could I set the cursor at the end of the text: Hello|
?
Use this plugin: http://plugins.jquery.com/project/PutCursorAtEnd
I think you are looking for selectionStart.
精彩评论