被动事件监听器 [英] Passive event listeners

查看:104
本文介绍了被动事件监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function loadMenuBasedScript() {}
var getMenuDependentValues="";
window.addEventListener("DOMContentLoaded", function() {
  document.getElementById("selectMenu").onchange = function() {
    menuSelected = this.value;
    loadMenuBasedScript(menuSelected, getMenuDependentValues);
  };
}, false);

<body>
  <div>
    <select id="selectMenu">
      <option value="one">One</option>
      <option value="two">Two</option>
    </select>
  </div>
</body>

如果我单击菜单图标,Chrome会在控制台中显示警告:

If I click the menu icon, chrome shows a warning in the console:

[Violation]向滚动阻止的"mousewheel"事件添加了非被动事件侦听器.考虑将事件处理程序标记为被动",以使页面更具响应性.请参见 https://www.chromestatus.com/feature/5745543795965952

如何通过简单的 html js 克服?我需要基于所选菜单的 value .

How to over overcome with simple html and js? I need the value based on the menu selected.

推荐答案

这只是Chrome的问题.即使仅使用< select></select> 而没有事件侦听器,也会发生这种情况.每当发生滚动阻止事件时,Chrome都会自动记录日志.使用Chrome的DevTools,我检查了选择框上是否没有鼠标滚轮侦听器,并且它仍然会发生.

This is just a problem with Chrome. It happens even with only <select></select> and no event listeners. Chrome automatically logs whenever a scroll-blocking event occurs . Using Chrome's DevTools, I checked that there is no mousewheel listeners on the select box, and it still happens.

我建议在控制台中关闭详细".

I suggest turning off 'Verbose' in the console.

这篇关于被动事件监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆