当页面上的某个元素失去焦点时,焦点总是会转移到其他地方;模糊事件的处理程序接收一个事件对象,但我没有看到任何东西告诉我焦点在哪里。
我怎样才能找到它?
最佳答案
您应该看看:https://developer.mozilla.org/en/XUL_Tutorial/Focus_and_Selection
有一个名为“获取当前焦点元素”的部分,它准确地解释了如何通过以下代码实现您所需要的:
function init(){
addEventListener("focus",setFocusedElement,true);
}
function setFocusedElement(){
var focused = document.commandDispatcher.focusedElement;
document.getElementById("focused").value = focused.tagName;
}
祝你好运!
关于javascript - 焦点去哪儿了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5919914/