Home > Web Front-end > JS Tutorial > js sample code to set the focus position in the text box at the end (simple and practical)_javascript skills

js sample code to set the focus position in the text box at the end (simple and practical)_javascript skills

WBOY
Release: 2016-05-16 16:57:28
Original
1106 people have browsed it

You can use this.focus(); directly in Firefox browser.

In IE, after this.focus();, assign the value of the text box to the text box, and the focus will be at the end. It's very simple! !

For example:

Copy code The code is as follows:

var tar=document.getElementByIdx_x( "name");
if(tar.attachEvent){
tar.attachEvent('onmouseover',focus(tar),false);
}else{
tar.addEventListener('mouseover' ,focus(tar),false);
}
function focus(tar){

tar.focus();
tar.value=tar.value;
}

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