捕获兼容问题

问题:在项目开发时,有时需要获取  冒泡或捕获  过程的所有元素

解决方案:

1、Chrome通过event.path获取:

const ev = window.event || event;
const path = ev.path;

2、Firefox和Safari中获取

const ev = window.event || event;
const path = event.composedPath && event.composedPath();

最终解决方案:

const ev = window.event || event;
const path = event.path || (event.composedPath && event.composedPath());

※随手附上应用代码

 

posted @ 2021-06-16 19:16  赛德·乌漆嘛黑  阅读(44)  评论(0编辑  收藏  举报