jquery Event.stopPropagation() seems not to work

前端 未结 1 553
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 04:53

Am I totally missing what this is supposed to do? I expect that if I call stopPropagation() on an event, handlers for that event won\'t get triggered on ancestor elements, b

1条回答
  •  眼角桃花
    2020-11-30 05:22

    Live events don't follow the same event bubbling rules. See the documentation on live event handling.

    Quote from reference above:

    Live events do not bubble in the traditional manner and cannot be stopped using stopPropagation or stopImmediatePropagation. For example, take the case of two click events - one bound to "li" and another "li a". Should a click occur on the inner anchor BOTH events will be triggered. This is because when a $("li").bind("click", fn); is bound you're actually saying "Whenever a click event occurs on an LI element - or inside an LI element - trigger this click event." To stop further processing for a live event, fn must return false.

    0 讨论(0)
提交回复
热议问题