解决移动端touch事件与click冲突的问题

最简单的办法,就只绑定一个事件不就行了;

第二种,我觉得和第一种也没啥区别。。

const Button = document.getElementById("targetButton");
 
const clickEvent = (function() {
  if ('ontouchstart' in document.documentElement === true)
    return 'touchstart';
  else
    return 'click';
})();
 
Button.addEventListener(clickEvent, e => {
  console.log("things happened!");
})
原文地址:https://www.cnblogs.com/xinsir/p/10475129.html