js如何判断设备类型(是否可以触屏)

判断浏览器是否支持touch事件

touch事件嘛,和click事件不一样,最起码设备得支持,要是PC端使,方法全不执行咋整,所以先来个判断。

('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch

这个方法,对于支持触摸事件的浏览器,返回值是 true ,不支持的,就是 undefined 了。

猜你喜欢

转载自blog.csdn.net/qq_42931285/article/details/128091096