jQuery手风琴防止冒泡/允许默认链接操作 [英] jquery accordion prevent bubbling / allow default link action
问题描述
我的手风琴设置如下:
$('.shortheadline').accordion({ active: false, header: '.headline', autoHeight: false, animated: 'slowslide', changestart: function(event, ui) { $('.brief').css('min-height','0') }, change: function(event, ui) { $('.brief:visible').css('min-height','80px'); $('.headline').blur(); } });
我希望点击仅在.headline div上注册,而不在其中的链接上注册.该链接会将您带到文章页面.
I want the click to only register on the .headline div, not the link inside. The link should take you to the article page.
<div class="shortheadline">
<div class="entry">
<div class="headline">
<div class="timestamp">11:34 AM</div>
<div class="title"><a href="http://beta.macobserver.com/tmo/article/jeff_gamet_shares_iphone_tips_and_tricks_on_macjury/">Jeff Gamet Shares iPhone Tips and Tricks on MacJury</a></div>
</div>
<div class="brief">
<div class="teaser_image"> <img src="/imgs/cache/imgs/teaser_images/20090708macjury_new-0x80.png" width="80" height="80" id="teas_48236" alt="macJuryJeff Gamet Shares iPhone Tips and Tricks on MacJury" /></div>
<div class="teaser"><p><em>The Mac Observer's</em> Jeff Gamet joined <em>MacJury</em> host Chuck Joiner to talk about Apple's iPhone OS 3.0, the iPhone 3GS, and to share some iPhone tips and tricks, too.</p> </div>
</div>
</div>
<!-- more entries -->
</div>
是否有一种方法可以防止事件冒泡,使手风琴仅在单击div时触发? 还是有办法允许链接的默认操作继续?
Is there a way to prevent event bubbling so the accordion only triggers on clicking a div? Or is there a way to allow the link's default action to continue?
我尝试过:
$("a").click(function(){ window.location=this.href; });
具有链接功能,但不允许用户在新标签页/窗口中打开链接.
Which does make the link function, but it doesn't let the user open the link in a new tab/window.
谢谢!
推荐答案
尝试
$("a").click(function(event){ event.stopPropagation(); });
click函数传递了一个事件"对象.通过调用事件对象的"stopPropagation"方法,可以防止冒泡.
The click function is passed an 'event' object. By calling the 'stopPropagation' method of the event object, you can prevent bubbling.
这篇关于jQuery手风琴防止冒泡/允许默认链接操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!