preventDefault()
方法
$(“a”).click(function(event){
alert( event.isDefaultPrevented() );
event.preventDefault();
alert( event.isDefaultPrevented() );
});$(“p”).click(function(event){
event.stopPropagation();
// do something
});stopPropagation()
方法
$(“p”).click(function(event){
alert( event.isPropagationStopped() );
event.stopPropagation();
alert( event.isPropagationStopped() );
});$(“p”).click(function(event){
event.stopImmediatePropagation();
});
$(“p”).click(function(event){
// This function won’t be executed
});stopImmediatePropagation()
方法
$(“p”).click(function(event){
alert( event.isImmediatePropagationStopped() );
event.stopImmediatePropagation();
alert( event.isImmediatePropagationStopped() );
});这些函数中 stopPropagation() 是我们最长用的也是一定会用到的函数. 相当于操作原始event对象的event.cancelBubble=true来取消冒泡.










