开发者

Where is the focus going?

When an element on a page loses focus, the focus always goes somewhere else; the handler for the blur event receives an event object but I don't see anything 开发者_开发百科in there that tells me where the focus is going.

How can I find that out?


You should have a look at: https://developer.mozilla.org/en/XUL_Tutorial/Focus_and_Selection

There's a section called 'Getting the currently focused element' which explains exactly how to achieve what you need, via the following code:

function init(){
  addEventListener("focus",setFocusedElement,true);
}

function setFocusedElement(){
  var focused = document.commandDispatcher.focusedElement;
  document.getElementById("focused").value = focused.tagName;
}

Good luck!


here's at least a partial answer: you can hook the /mousedown/ event, which bubbles up and which occurs before focus actually changes. if the user hits a tab instead of using the mouse, I don't know how it can be done!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜