本文介绍了如何确定重点在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已被要求,但几年前,当时没有跨平台的解决方案(除了 setTimeout 解决方案,这真的不是很方便)。



我想做 onblur =foo(parm);并且有 foo 能够确定哪个元素现在拥有焦点。



我正在使用常规javascript;没有jQuery这一个,请。

这些日子可能吗?

解决方案


 函数whereDidYouGo(){
var all = document.getElementsByTagName ( '*'); (所有[i] ===所有[i] .ownerDocument.activeElement)
(var i = 0; i< all.length; i ++)


全部返回[i];

$ / code>

编辑:

 函数whereDidYouGo(){return document.activeElement; } 


This has been asked here before, but several years ago, and there was no cross-platform solution at the time (other than the setTimeout solution, which is really not very handy).

I'd like to do onblur="foo(parm);" and have foo be able to determine which element now has focus.

I'm using regular javascript; no jQuery for this one, please.

Is that possible these days?

解决方案

You can try something like this:

function whereDidYouGo() {
    var all = document.getElementsByTagName('*');

        for (var i = 0; i < all.length; i++)
            if (all[i] === all[i].ownerDocument.activeElement)
                return all[i];
}

EDIT:

function whereDidYouGo() { return document.activeElement; }

这篇关于如何确定重点在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 21:36