찾다

 >  Q&A  >  본문

javascript - 怎么阻止js的touch事件冒泡

我在父元素绑定了touchstart,touchmove和touchend事件,在子元素绑定了touchstart事件,触摸子元素的时候会触发父元素的事件,而stopPropagation并不能阻止touchend,怎么做比较好

黄舟黄舟2896일 전334

모든 응답(2)나는 대답할 것이다

  • 高洛峰

    高洛峰2017-04-10 15:20:54

    试试

    event.stopImmediatePropagation();

    不过冒泡估计没办法去阻止了。最好检查状态改变
    还有如果touch的是元素的margin就不会bubble
    .

    회신하다
    0
  • 巴扎黑

    巴扎黑2017-04-10 15:20:54

    子元素的touchend也stopPropagation

    회신하다
    0
  • 취소회신하다