gpt4 book ai didi

javascript - Edge 的composedPath 的替代方案

转载 作者:行者123 更新时间:2023-12-01 00:33:15 27 4
gpt4 key购买 nike

我希望当我使用 Edge/IE 单击某处时能够检测到路径。与all other browsers我可以使用event.composedPath() ,但 Edge 和 IE 不支持。

我环顾四周,只发现 found pages不鼓励使用 path 并使用 composedPath() 代替,但我没有找到 Edge 的任何引用。

请帮忙!

最佳答案

您可以尝试检查这个polyfill是否有助于获取组合路径。

// Event.composedPath
(function(e, d, w) {
if(!e.composedPath) {
e.composedPath = function() {
if (this.path) {
return this.path;
}
var target = this.target;

this.path = [];
while (target.parentNode !== null) {
this.path.push(target);
target = target.parentNode;
}
this.path.push(d, w);
return this.path;
}
}
})(Event.prototype, document, window);

像下面这样使用它:

var path = event.path || (event.composedPath && event.composedPath());

引用文献:

(1) event.path undefined with Firefox and Vue.js

(2) rockinghelvetica/composedpath.polyfill.js

除此之外,我没有任何替代方案或解决方法来获取 IE 和 Edge 浏览器的 Event.Comlatedpath。

关于javascript - Edge 的composedPath 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58344817/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com