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.