首页 > 解决方案 > Chrome - 由于目标被视为被动,无法在被动事件侦听器中阻止默认值

问题描述

我在下面使用 chrome 时遇到错误

错误:

[干预] 由于目标被视为被动,无法阻止被动事件侦听器内部的默认值。看url

代码:

$('body').on("wheel", "form input[type=number]", function (e) {
    e.preventDefault();
});

如果用户在数字输入字段内使用鼠标滚轮,上面的代码用于防止对数字字段进行更改。

我最近收到此错误,前几天没有此类错误!

*更新:

我试过添加

{
    passive: true
}

像这样:

$('body').on("wheel", "form input[type=number]", function (e) {
    e.preventDefault();
}, {passive: true});

另一个错误显示:

jquery.min.js:3 Uncaught TypeError: ((r.event.special[g.origType] || {}).handle || g.handler).apply is not a function
    at HTMLBodyElement.dispatch (jquery.min.js:3)
    at HTMLBodyElement.q.handle (jquery.min.js:3)

如何修复错误并防止数字字段内的鼠标滚轮?

铬版: Chrome 78 on Windows 10

标签: javascriptjquerygoogle-chrome

解决方案


推荐阅读