问题描述
使用jQuery:使用下面的代码我想防止href url(在这种情况下是一个散列'#')被点击,但仍然允许点击事件继续冒泡链。如何实现?
< div>
< a href =#>测试< / a>
< / div>
$('a')。click(function(e){
//停止a.click触发,但允许点击事件继续冒泡?
$ 'a')。click(function(e){
e.preventDefault();
// stop a.click firing but allow click event to continue bubbling?
Using jQuery: with the following code I'd like to prevent the href url (in this case a hash '#') being fired on click, but still allow the click event to continue bubbling up the chain. How can this be achieved please? 这篇关于如何防止默认事件触发,但仍允许事件冒泡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! e.preventDefault防止冒泡,
e.stopPropagation()
或返回false
b<div>
<a href="#">Test</a>
</div>
$('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()
won't prevent bubbling, e.stopPropagation()
or return false
(stop both) will.