检查某个元素是否被“聚焦”没有jQuery [英] Check whether some element is "focused" without jQuery
本文介绍了检查某个元素是否被“聚焦”没有jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查事件调用时是否有某个对象被选中(关注)?我试图
如果(document.activeElement == [对象HTMLBodyElement])
,但显然 .activeElement
是被填充onLoad。我不允许使用jQuery,只mootools的。 非常感谢您的帮助!
解决方案
https://developer.mozilla.org/en/DOM /document.activeElement - 正如所指出的那样,如果没有元素被关注,默认情况下文档正文是关注的:
if(document.activeElement!= document.body){
//除了正文以外的其他内容
}
I was almost sure I could find the answer here, but I wasn't successful.
How would you check whether is there some object selected (focused) on the moment of the event call? I tried if (document.activeElement == "[object HTMLBodyElement]")
, but apparently the .activeElement
is being filled onLoad. I am not allowed to use jQuery, only mootools.
Thanks a lot for the help!
解决方案
https://developer.mozilla.org/en/DOM/document.activeElement - as pointed out, if no element is focused, the document body is focused by default:
if (document.activeElement != document.body) {
// something else than the body is focused
}
这篇关于检查某个元素是否被“聚焦”没有jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文