jQuery.Event提供了一個非常簡單的方法來阻止事件冒泡:event.stopPropagation();
$("p").click(function(event){
event.stopPropagation(); // do something
})
但是這個方法對使用live綁定的事件沒有作用,需要一個更簡單的方法阻止事件冒泡:return false;
$("p").live("click", function(){
$(this).after("Another paragraph!");
return false;
});
注意:jquery-1.6.2.min.js 這個版本不支持return false; 換成jquery-1.8.3.js這個版本的就成了。