跃然一笑
HTML:<button id="clear">clear log</button><div id="event"></div>使用Javascript:$(function(){ $hasFocus = false; $('#clear').bind('click', function() { $('#event').empty(); }); $(window) .bind('focus', function(ev){ $hasFocus = true; $('#event').append('<div>'+(new Date()).getTime()+' focus</div>'); }) .bind('blur', function(ev){ $hasFocus = false; $('#event').append('<div>'+(new Date()).getTime()+' blur</div>'); }) .trigger('focus'); setInterval(function() { $('#event').append('<div>'+(new Date()).getTime()+' has focus '+($hasFocus ? 'yes' : 'no')+'</div>'); }, 1000);});