解决移动端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!");
})

 

posted @ 2019-03-05 10:30  tomatoa  阅读(1592)  评论(0编辑  收藏  举报