你如何清除焦点在JavaScript?
我知道这不应该那么难,但我在Google上找不到答案。
我想要执行一段JavaScript,它将清除所关注的任何元素的焦点,而不必提前知道焦点所在的元素。 它必须工作在Firefox 2以及更现代的浏览器。
有没有一个好的方法来做到这一点?
 .focus() ,然后是.blur()在你的页面上任意的东西。 由于只有一个元素可以获得焦点,所以它被转移到该元素上,然后被移除。 
 答案是: document.activeElement 
– -编辑 – –
 技术上来说: document.activeElement.blur() 
—-编辑2 —-
 function onElementFocused(e) { if (e && e.target) document.activeElement = e.target == document ? null : e.target; } if (document.addEventListener) document.addEventListener("focus", onElementFocused, true); 
 document.activeElement.blur(); 
在IE9上工作不正确 – 如果活动元素是文档主体,则模糊整个浏览器窗口。 最好检查这种情况:
 if (document.activeElement != document.body) document.activeElement.blur(); 
dummyElem.focus()其中dummyElem是一个隐藏的对象(例如负zIndex)?
你可以调用window.focus();
但移动或失去焦点必然会干扰任何使用Tab键来绕过页面的人。
你可以听到键码13,并放弃如果按Tab键的效果。
这个问题可能会给你一些答案。