zoukankan      html  css  js  c++  java
  • activeElement在safari与chrome总是返回body?

    现在都支持document.activeElement属性 ,但是在safari与chrome出现了些状况……到stackoverflow查了一下,但给出的方法并不靠谱,因为click事件总是赶在focus事件前发生。

    //http://stackoverflow.com/questions/483741/how-to-determine-which-html-page-element-has-focus
    function _dom_trackActiveElement(evt) {
        if (evt && evt.target) { 
            document.activeElement = evt.target == document ? null : evt.target;
        }
    }
    
    function _dom_trackActiveElementLost(evt) { 
        document.activeElement = null;
    }
    
    if (!document.activeElement) {
        document.addEventListener("focus",_dom_trackActiveElement,true);
        document.addEventListener("blur",_dom_trackActiveElementLost,true);
    }
    

    在标准浏览器支持一个叫DOMActivate,但同样太慢了,帮不上忙。

    注意,我的目的是想获取当前激活元素,并不是想得到当前的点击的元素……

    记得我以前好像在背光博客见过这种机制的解析,但此博客在河蟹浪潮中覆灭了……

  • 相关阅读:
    iOS开发tips-UITableView、UICollectionView行高/尺寸自适应
    10559
    日志系统之基于Zookeeper的分布式协同设计
    IOS 图片上传处理 图片压缩 图片处理
    istream, outstream使用及常见错误
    matlab 扩大虚拟内存
    github不小心同步覆盖了本地文件
    经典统计语言模型
    Makefile 快速入门
    word2vec——高效word特征提取
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1659274.html
Copyright © 2011-2022 走看看