开发者

Debugging issues : detect where my focus is with jQuery?

开发者 https://www.devze.com 2023-01-19 01:18 出处:网络
Forcing focus() on an element is easy, but after having debug issues, I realize trying to d开发者_如何学编程etermine where is my focus gone is a lot harder.

Forcing focus() on an element is easy, but after having debug issues, I realize trying to d开发者_如何学编程etermine where is my focus gone is a lot harder. The thing is I'm generating a modal window using jq.UI, and from time to time, while focus is supposed to be set on first input of the form included in the modal, cursor just disappears, to never show again unless I reload the page.

Is there a straightforward way to detect where my focus/cursor is?


You can see which element it's on by checking document.activeElement, for example:

alert(document.activeElement.innerHTML); //see the content to aid in IDing it


I'm not sure if the focus event bubbles, but if it does, you could try this:

jQuery('body').focus(function(e){ console.log(e.target); })
0

精彩评论

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