小编Tel*_*bov的帖子

event.preventDefault 不适用于 Chrome 中的“document”/“document.body”元素

我有一些功能可以防止设备上的触摸事件(在某些特定情况下)。它运行良好,直到最后一次更新 Chrome。

更新后,试图阻止我从中获得documentdocument.body不再工作的事件,但如果我从某个特定元素侦听事件,它会起作用。

例如:

//this not works
document.addEventListener("touchmove", function(event) {
    event.preventDefault();
});

//this one works
document.querySelector(".container").addEventListener("touchmove", function(event) {
    event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

这不是很方便的行为,因为我在body元素中有很多子元素并且无法更改此结构。

有没有人知道如何让它再次工作,或者它是最新 Chrome 的正确行为?将不胜感激任何帮助,谢谢。

javascript google-chrome touch-event

3
推荐指数
1
解决办法
1977
查看次数

标签 统计

google-chrome ×1

javascript ×1

touch-event ×1