When the input box (Input/textarea) Gets the focus, it moves the focus to the end, and in some cases the user experience is good. Most of the methods on the Internet are for IE browsers. The code is as follows:
var el = Document.getelementbyid ( ' txtarticle ' var range = El.createtextrange ( Range.movestart ( ' character ', El.value.length);
Range.collapsefalse Range. select (
In fact, you can delete the MoveStart line, because the createTextRange method creates a range, using the Collapse method, the parameter is false to move to the last. Collapse (true) moves the cursor to the beginning of range, collapse (false) moves the cursor to the end of range. Standard browsers such as Firefox can use the Setselectionrange method. The code is as follows:
var range, el =document.getElementById(' Txtphone ');
if (El.setselectionrange{
el.focus el.setselectionrange (el.value.length, El.value.length"
} else {
range = El.createtextrange ( range.collapsefalse range. select ( /span>
Note The Setselectionrange method applies only to Input/textarea elements. The focus of other non-native editable elements moves to the collapse method that can take advantage of the Selection object, for example:
var sel, el = document.getElementById(' hint ');
sel = window. GetSelection();
Sel.collapse(el, 1);
ElFocus();
JS move focus to the end