zoukankan      html  css  js  c++  java
  • JavaScript事件起泡与捕获

    // 向 <div> 元素添加事件句柄
    document.getElementById("myDIV").addEventListener("mousemove", myFunction);
    
    // 移除 <div> 元素的事件句柄
    document.getElementById("myDIV").removeEventListener("mousemove", myFunction);

    addEventListener() 方法用于向指定元素添加事件句柄。

    element.addEventListener(event, function, useCapture)  //语法

    useCapture:可选。布尔值,指定事件是否在捕获或冒泡阶段执行。

    • true - 事件句柄在捕获阶段执行
    • false- false- 默认。事件句柄在冒泡阶段执行

    事件捕获阶段capture phase,传播顺序:window -> 事件源的父元素.  The event object must propagate through the target's ancestors from the Window to the target's parent.

    事件冒泡阶段bubble phase,传播顺序:事件源父元素 -> window.  The event object propagates through the target’s ancestors in reverse, starting with the target's parent and ending with the Window. 

    目标阶段target phase:事件对象到达事件源。The event object arrive at the event object's event target.

     可参考相关文章 : https://www.cnblogs.com/zhuzhenwei918/p/6139880.html

                                  http://blog.csdn.net/qq_28602957/article/details/60475123

  • 相关阅读:
    深入理解sizeof
    trie树详解
    高精度计算
    编写高效的Android代码
    Android Architecture
    AIDL Android中的远程接口
    性能测试常见术语
    软件与软件测试相关
    注解实现Springmvc+jsp步骤
    非注解实现SpringMvc+JSP (一般用不到 主要用于了解研究底层)
  • 原文地址:https://www.cnblogs.com/yongwangzhiqian/p/6640331.html
Copyright © 2011-2022 走看看