如何防止默认事件触发但仍允许事件冒泡

使用jQuery:使用以下代码我想阻止href url(在这种情况下为散列’#’)在点击时被触发,但仍然允许click事件继续冒泡链。 怎么能实现呢?

 $('a').click(function(e){ // stop a.click firing but allow click event to continue bubbling? }); 

 $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); 

e.preventDefault()不会阻止冒泡, e.stopPropagation()return false (停止两者)将。

你可以这样做:

 $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); 

在这里摆弄http://jsfiddle.net/tU53v/

试试这个..

 $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); 

在这里你可以找到return falsee.preventDefault();之间的区别e.preventDefault();