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

Ste*_*eve 8 jquery events click event-bubbling

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

<div>
    <a href="#">Test</a>
</div>

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

She*_*hef 9

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

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