导航


HTML

CSS

JavaScript

浏览器 & 网络

版本管理

框架

构建工具

TypeScript

性能优化

软实力

算法

UI、组件库

Node

业务技能

针对性攻坚

AI


事件对象

var container = document.querySelector('.container');
container.addEventListener('click', function(e) {
  console.log(e);
});

// [pointerEvent]PointerEvent ->
// MouseEvent.prototype ->
// UIEvent.prototype ->
// Event.prototype ->
// Object.prototype

Untitled

🔥 event.target 和 event.currentTarget 的区别

Untitled

Untitled

在上述事件冒泡中:

  1. 点了子元素 #btn(target)
  2. 事件会往外冒泡到父元素 .wrapper
  3. 但父元素也能收到这个事件(currentTarget)

结果: