Skip to content

利用 document.activeElement 获取焦点元素

document.activeElement

document.activeElement 三大浏览器 (ie、firefox、chrome) 都支持,但,针对的对象不同,返回的值也不同。

IE:

document.activeElement 可获得所有聚焦的元素,包括 input、textarea、div 等。IE 只关心光标聚焦的位置,不关心聚焦元素的性质。

Chrome:

document.activeElement 仅对 input、textarea 等标准的输入文本有效;对于 div 等非编辑类的元素(即使开启了 contentEditable),返回的值为 BODY。

FireFox:

document.activeElement 可获得所有聚焦的元素。包括 input、textarea、div 等。

最后编辑时间:

Version 4.0 (framework-1.0.0-rc.20)