简体   繁体   English

调试问题:使用 jQuery 检测我的重点在哪里?

[英]Debugging issues : detect where my focus is with jQuery?

Forcing focus() on an element is easy, but after having debug issues, I realize trying to determine where is my focus gone is a lot harder.在元素上强制使用focus()很容易,但在遇到调试问题后,我意识到试图确定我的焦点在哪里消失了要困难得多。 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.问题是我正在使用 jq.UI 生成一个模态窗口,并且不时地,虽然应该在模态中包含的表单的第一个输入上设置焦点,但光标会消失,除非我重新加载,否则永远不会再次显示页面。

Is there a straightforward way to detect where my focus/cursor is?有没有一种直接的方法来检测我的焦点/光标在哪里?

您可以通过检查document.activeElement来查看它所在的元素,例如:

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

我不确定焦点事件是否冒泡,但如果冒泡,您可以尝试以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM