仅当元素具有特定的 class 时检测 touchstart
detect touchstart only if element has a specific class
我正在监听 JQuery 的事件,如下所示:
$(document).on('click touchstart', '.open-qv', function(e){
e.preventDefault();
但是我只想听 for/detect touchstart
如果触摸的元素具有特定的 class 例如。 .hotspot
如果没有这个 class 我只想听点击,有没有办法做到这一点?
您应该使用 event.type
检查事件不是 touchstart 或元素 .hasClass()
hotspot:
$(document).on('click touchstart', '.open-qv', function(e){
if(event.type!="touchstart" || $(this).hasClass('hotspot') ){
//do stuff
}
我正在监听 JQuery 的事件,如下所示:
$(document).on('click touchstart', '.open-qv', function(e){
e.preventDefault();
但是我只想听 for/detect touchstart
如果触摸的元素具有特定的 class 例如。 .hotspot
如果没有这个 class 我只想听点击,有没有办法做到这一点?
您应该使用 event.type
检查事件不是 touchstart 或元素 .hasClass()
hotspot:
$(document).on('click touchstart', '.open-qv', function(e){
if(event.type!="touchstart" || $(this).hasClass('hotspot') ){
//do stuff
}