链接是在可以点击的div中,如何解决链接的点击问题?


我想实现的是,有一个< a >在< div > 里面,然后我给这个div 加了一个 .click(function() {}); 的事件。

代码如下:

$('div.feature').click(function() { window.location = $(this).attr('rel');});

div代码如下:

<div id="feature" rel="urlnumberone">
some text
<a href="javascript:topicchange(this);" class="insideLink">Link</a>
</div>

如果我使用如下代码:

$('.insideLink').click(function(event){
    event.stopImmediatePropagation();
});

不能正常工作。

有什么办法可以不让div 的 click执行吗?谢谢。

事件传递 开发 前端 js

吸血鬼铁拳 9 years, 7 months ago

添加一个nobubble class到你的< a >。然后在html中加入以下jquery 代码:

$('.nobubble').click(function(event){
    event.stopImmediatePropagation();
});
侵略-青蛙子 answered 9 years, 7 months ago

Your Answer