检测touchstart只有元素有一个特定的类
问题描述:
我留神听与jQuery的事件如下:检测touchstart只有元素有一个特定的类
$(document).on('click touchstart', '.open-qv', function(e){
e.preventDefault();
但是我只是想监听/检测touchstart
如果元素感动了特定类如。 .hotspot
如果它没有这个类,我只想听点击,有没有办法做到这一点?
答
您应该使用event.type
检查这两种情况下不touchstart或元素.hasClass()
热点:
$(document).on('click touchstart', '.open-qv', function(e){
if(event.type!="touchstart" || $(this).hasClass('hotspot')){
//do stuff
}