关注图老师设计创意栏目可以让大家能更好的了解电脑,知道有关于电脑的更多有趣教程,今天给大家分享event.currentTarget和document.activeElement用法教程,希望对大家能有一点小小的帮助。
【 tulaoshi.com - Web开发 】
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)
firefox 的 event.currentTarget 和 ie 的 document.activeElement 这两个完全含义不一致的对象却被捆绑在一起做成了浏览器兼容代码。 大家在的时候 都会发现 document.activeElement || event.currentTarget 的用法。
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)其实这样的用法是错误的,因为这两个属性的意义都不一样。
Identifies the current target for the event, as the event traverses the DOM.
识别当前事件触发的dom
Gets the object that has the focus when the parent document has focus.
获得当前focus的对象
例子
script type="text/javascript"最后测试补充:后来测试了一下 document.activeElement 的支持程度,发现四大浏览器safari除外, ie firefox opera都提供了这个对象的支持。但是有点需要注意的,上面的例子中 opera 会把图片作为 可以 focus的对象。导致document.activeElement的结果不一致...
来源:http://www.tulaoshi.com/n/20160219/1630218.html
看过《event.currentTarget和document.activeElement用法》的人还看了以下文章 更多>>