Created
August 31, 2018 15:50
-
-
Save bigxixi/d900de1608b42f143189433a521f0840 to your computer and use it in GitHub Desktop.
判断click和touch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") | |
}) | |
//作者:libinfs | |
//链接:https://juejin.im/post/5aa09afe51882555602077be | |
//来源:掘金 | |
//著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment