我完全错过了它应该做什么吗?我希望如果我在某个事件上调用 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.
关于jquery Event.stopPropagation() 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1122375/