• 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,但同样太慢了,帮不上忙。

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

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

  • 相关阅读:
    Three.js 类的粗略总结和实现
    JavaScript方法
    JavaScript 继承和数组
    JavaScript 函数
    操作系统之堆和栈的区别
    第十二章 动态内存
    第十三章-第六小节-对象移动
    第十五章 面形对象程序设计
    动态建树和静态建树
    高斯消元整数版和浮点数版实现
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1659274.html
Copyright © 2020-2023  润新知