HTML:document.activeElement

今天遇到一个很郁闷的问题:

 

document.activeElement获取当前获得焦点的元素,在chrome总是得到body,后来经过试验得到结果如下:

 

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等。

 

有许多奇怪的问题,随后再补充。

posted on 2014-08-27 17:28  Hugh_txp  阅读(462)  评论(0编辑  收藏  举报