Home  >  Article  >  Web Front-end  >  Solution to js focus not working (mainly because the dom element is loaded)_javascript skills

Solution to js focus not working (mainly because the dom element is loaded)_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:16:492011browse

There is a text box with an id of d. Use the following js code to get it focused.

document.getElementById("d").focus();
The resulting code does not work in IE. To get focus in IE, you need to use code similar to the following:

Copy code The code is as follows:

document.body.onload = function(){
document.getElementById("d").focus();
}
Statement:
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