window.onblur事件在使用IE8时也会触发window.onfocus事件
这两件事都在onblur事件中被解雇了。
window.onfocus = function() { $('#msg').html($('#msg').html() + '
focus'); }; window.onblur = function() { $('#msg').html($('#msg').html() + '
Blur'); };
最后它解决了。 谢谢你的帮助!
$(window).bind("load", function() { pageLoad(); }); var activeElement; function pageLoad() { activeElement = document.activeElement; document.onfocusout = logWindow; } function logWindow() { if (activeElement != document.activeElement) { activeElement = document.activeElement; } else { $('#msg').html($('#msg').html()+'
Focus'); } }
window.onblur = function() { $('#msg').html($('#msg').html() + '
Blur'); return false; };
可能是事件正在冒泡。