Copy Code code as follows:
<script>
When the intersection is lost, let the text in the TextBox get the focus and the cursor moves behind the last word.
function Myfocus (myID) {
if (Isnav) {
document.getElementById (myID). focus ();//Get focused
}else{
Setfocus.call (document.getElementById (myID));
}
}
var Isnav = (Window.navigator.appName.toLowerCase (). IndexOf ("Netscape") >=0);
var Isie = (Window.navigator.appName.toLowerCase (). IndexOf ("Microsoft") >=0);
function SetFocus () {
var range = This.createtextrange (); Create a text selection
Range.movestart (' character ', this.value.length); The beginning of the selection moves to the last
Range.collapse (TRUE);
Range.Select ();
}
</script>
Example:
This is a fuzzy search with Ztree.
At first all the tree nodes are closed, but if the input search content when the query, expand the query content of the parent node, will make the input inside the loss of focus, the user experience is not good, here in the parent node, and then let input gain focus, if only the use of focusing () , the cursor appears at the front of the text box. Of course, this is not the effect I want. Call the above code, you can implement after the query, the cursor positioned behind the query text.