首页 > touchend事件阻止冒泡e.target==this设置无效,不在一个层级的元素仍然会被触发?

touchend事件阻止冒泡e.target==this设置无效,不在一个层级的元素仍然会被触发?

$(".model-full,.close-model").on("touchend",function(e){
    if(e.target==this){
      $(".model-full").fadeOut();
      $(".ctm-container,.close-model").hide();
      $('#css').remove();
    }
});

效果图:

元素css:

现在点击.ctm-container还是会隐藏.model-full和.ctm-container,为什么用了e.target还是没用,以前电脑端上用这个方法都是可行的。有谁知道是什么原因呢?求解决方案,谢谢!


不是冒泡问题。a链接刷新了页面。。。


求项目地址和源码 哈哈


你代码里这两句不就是把两者都隐藏了吗?

$(".model-full").fadeOut();
$(".ctm-container,.close-model").hide();


可能是手机上,点击事件穿透问题,可以看下 https://.com/q/1010000003043546
fastclick 可以解决


e.target === $(this)


没太看明白问题~你试试e.currentTarge


阻止冒泡用 event.preventDefault() 或者 return false;

e.target == this ? console.log 输出下 这个判断有没有问题。。 或者可以通过 e.target.className nodeName 来尝试判断

【热门文章】
【热门文章】