开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜