Home >Web Front-end >JS Tutorial >Solution to focus and blur confusion under IE6_javascript skills

Solution to focus and blur confusion under IE6_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 18:04:031094browse
Copy code The code is as follows:



hello
<script> <br>(function(){ <br>var focusTimer = 0; <br>function myBlur(){ <br>document. title= 'blur:' Math.random() ; <br>} <br>function myFocus(){ <br>clearTimeout(focusTimer); <br>focusTimer = setTimeout(function(){ <br>document.title = 'focus:' Math.random() ; <br>},10); <br>} <br>window.onfocus = document.body.onfocusin = myFocus; <br>window.onblur = document.body.onfocusout = myBlur; <br>}()); <br></script>


The general principle is: find many opportunities that may trigger onfocus and onblur, all The onblur is executed immediately, while the onfocus is executed lazily with a delay of 10 milliseconds.
The result is: although myFocus and myBlur are sometimes executed several times more, the correctness of the window status can be guaranteed.
The method may be a bit copycat, but I didn’t think of a better way for the time being, so this can temporarily solve an urgent need.
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