简体   繁体   English

Chrome 中的禁用按钮仍会在触摸时触发

[英]Disabled button still fires on touch in Chrome

In the Chrome browser, I noticed disabled button elements are still firing when using 'touchend' or 'pointerup' events.在 Chrome 浏览器中,我注意到在使用“touchend”或“pointerup”事件时,禁用的按钮元素仍在触发。 I see this on Chrome desktop (mac) in device emulation mode and in Chrome on a Surface.我在设备仿真模式下的 Chrome 桌面 (mac) 和 Surface 上的 Chrome 中看到了这一点。 This doesn't seem to be problem on other browsers.这在其他浏览器上似乎不是问题。

// neither of these seem to have an effect on touch/pointer events
button.disabled = true;
button.setAttribute('disabled', 'disabled');

Obvious fix would to only mouse events, but I'd rather not have the lag time for it to trigger on touch devices.明显的修复只针对鼠标事件,但我宁愿没有延迟时间让它在触摸设备上触发。 I'm assuming this a Chrome issue and not my code, but I thought I'd ask to see maybe it is me or if others have found a practical work around.我假设这是一个 Chrome 问题,而不是我的代码,但我想我想看看可能是我,或者其他人是否找到了实用的解决方法。

I was facing same problem and as suggested by @bigless, below CSS worked for me too.我遇到了同样的问题,正如@bigless 所建议的那样,CSS 下面也对我有用。

button:disabled { pointer-events: none };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM