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

  • 相关阅读:
    Building a ListBox with custom content in Silverlight 4.0
    asp.net通讯问题
    Using the NavigationService Object in SL4.0
    Creating a File Explorer for Isolated Storage
    图表ASP:Chart
    什么是继承?
    Java基础一笔带过
    Java多态
    自己动手写个小框架之七
    linux crontab 定时计划
  • 原文地址:https://www.cnblogs.com/yongwangzhiqian/p/6640331.html
Copyright © 2011-2022 走看看