This article is mainly on the JS implementation of the text box focus in the final position of the sample code is introduced, the need for friends can come to the reference, I hope to help you
In a general program. When the programmer makes the content correctness test of the input box, it usually likes to determine the focus frame by judging the legality of the content. If: The code is as follows: if (obj.value== "") {Obj.focus (); return false; This will move the focus to the input box when the entry box is empty. This feature is very convenient to use. But there is a small problem ... That's Obj.focus () when you move the focus to the input box, you move the text cursor (that is, a flashing vertical line) to the position of the first character of the input box ... As far as the above judgment is concerned. If there is no content in the text box ... Obj.focus just satisfies the point where we can just type in the text box without clicking the text box to keep the text focused ... However, if there is already content in the text box ... But this content is illegal. Obj.focus () also moves the cursor to the position of the first character of the text box ... This will let the attention of the user experience of the designer depressed ... What we need is that the text box gets the focus, then the text cursor moves to the end of the text box, allowing the user to enter the content without clicking the text box. The input will be appended to the original content. The following code can complete this small detail: The code is as follows: <script language= "JavaScript" > function Getselectpos (obj) {var esrc = Document.getelementby Id (obj); if (esrc==null) {esrc=event.srcelement;} var rtextrange =esrc.createtextrange (); Rtextrange.movestart (' character ', esrc.value.length); Rtextrange.collapse (TRUE); Rtextrange.select (); </script> This code is a great help to designers in terms of the details of the user experience ...