我完全不知道这应该做什么吗?我希望如果我在一个事件上调用stopPropagation(),则该事件的处理程序将不会在祖先元素上触发,但下面的示例不能正常工作(至少在FireFox 3中)..
<script type="text/javascript"> $("input").live("click",function(event){ console.log("input click handler called") event.stopPropagation() }); $("body").live("click",function(event){ console.log("body was click handler called. event.isPropagationStopped() returns: " + event.isPropagationStopped()); }) </script> ... <body> <input type="text" > </body>
解决方法
现场活动不符合相同的事件冒泡规则。请参阅有关
live event handling的文档。
从上面引用的引用:
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.