JQuery click input to move the cursor to the last or specified position

Source: Internet
Author: User
You need to know that focus () is far from enough for a Virgo demander. For example, "When I click in, the cursor will be at the end, so that I don't have to move the cursor to the end to add anything ." Oh, let me hit the wall first. We need to extend jQuery: place the cursor at the end $ (# text box ID). textFocus (); place the cursor at the second character

You need to know that focus () is far from enough for a Virgo demander. For example, "When I click in, the cursor will be at the end, so that I don't have to move the cursor to the end to add anything ." Oh, let me hit the wall first. We need to extend jQuery: // place the cursor at the end $ ("# text box ID"). textFocus (); place the cursor at the second character

You need to know that focus () is far from enough for a Virgo demander.
For example, "When I click in, the cursor will be at the end, so that I don't have to move the cursor to the end to add anything ."
Oh, let me hit the wall first.
We need to extend jQuery:

// Place the cursor at the end $ ("# text box ID "). textFocus (); place the cursor behind the second character $ ("# text box ID "). textFocus (2); (function ($) {$. fn. textFocus = function (v) {var range, len, v = v === undefined? 0: parseInt (v); this. each (function () {if ($. browser. msie) {range = this. createTextRange (); v = 0? Range. collapse (false): range. move ("character", v); range. select ();} else {len = this. value. length; v = 0? This. setSelectionRange (len, len): this. setSelectionRange (v, v);} this. focus () ;}); return this ;}} (jQuery );

Another simple method:
Var t = $ ("#" + id). val ();
$ ("#" + Id). val (""). focus (). val (t );

The first method is recommended.

Original article address: Click input in jQuery to move the cursor to the last or specified position. Thank you for sharing it with the original author.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.