最简单的办法,就只绑定一个事件不就好了;app
第二种,我以为和第一种也没啥区别。。spa
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!"); })