Home > Web Front-end > JS Tutorial > JavaScript allows the back of the last text in the text box to gain focus implementation code_javascript skills

JavaScript allows the back of the last text in the text box to gain focus implementation code_javascript skills

WBOY
Release: 2016-05-16 17:44:20
Original
1107 people have browsed it
Copy code The code is as follows:

<script> <br>//Let the text disappear when the intersection is lost The text in the box gets focus and the cursor moves after the last word <br>function myfocus(myid) { <br>if(isNav){ <br>document.getElementById(myid).focus();// Get focus<br><br>}else{ <br>setFocus.call(document.getElementById(myid)); <br>} <br>} <br>var isNav = (window.navigator.appName.toLowerCase().indexOf( "netscape")>=0); <br>var isIE = (window.navigator.appName.toLowerCase().indexOf("microsoft")>=0); <br>function setFocus() { <br> var range = this.createTextRange(); //Create a text selection<br>range.moveStart('character', this.value.length); //Move the starting point of the selection to the end<br>range.collapse(true) ; <br>range.select(); <br>} <br></script>

Example:
JavaScript allows the back of the last text in the text box to gain focus implementation code_javascript skills
Ztree is used here Fuzzy search
All tree nodes are closed at the beginning, but if you query when entering the search content, and expand the parent node of the query content, the input will lose focus, and the user experience will be poor. Okay, here, after the parent node is expanded, let the input gain focus. If you just use focus(), the cursor will appear at the front of the text box. Of course this is not the effect I want. By calling the above code, you can position the cursor behind the query text after querying.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template