In the html element, textarea is a chicken rib. The obtained focus cursor cannot locate the last character. The author has a simple rich text box in the project, requiring users to enter characters and support emoticons at the same time. After an emoticon is selected, textarea obtains the focus, and the cursor stays at the top of textarea In the chrome browser. The conclusion is that different browsers have different focus implementations on the textare element.
The solution is as follows:
<Script type = "text/javascript"> function moveCaretToEnd (el) {if (typeof el. selectionStart = "number") {el. selectionStart = el. selectionEnd = el. value. length;} else if (typeof el. createTextRange! = "Undefined") {el. focus (); var range = el. createTextRange (); range. collapse (false); range. select () ;}} var textarea = document. getElementById ("test"); textarea. onfocus = function () {moveCaretToEnd (textarea); // Work around Chrome's little problem window. setTimeout (function () {moveCaretToEnd (textarea) ;}, 1) ;}; </script> <textarea id = "test"> Something </textarea>