jquery 手风琴防止冒泡/允许默认链接操作

发布于 2024-07-27 13:53:26 字数 1726 浏览 3 评论 0原文

我有一个手风琴设置:

 $('.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 上注册,而不是在内部链接上注册。 该链接应将您带到文章页面。

   <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 时触发? 或者有没有办法让链接的默认操作继续?

我已经尝试过:

$("a").click(function(){ window.location=this.href;  });

这确实使链接起作用,但它不允许用户在新选项卡/窗口中打开链接。

谢谢!

I have an accordion setup as so:

 $('.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(); } });

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>

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?

I've tried:

$("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.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁对谁错谁最难过 2024-08-03 13:53:26

尝试

$("a").click(function(event){ event.stopPropagation(); });

点击函数传递一个“事件”对象。 通过调用事件对象的“stopPropagation”方法,可以防止冒泡。

Try

$("a").click(function(event){ event.stopPropagation(); });

The click function is passed an 'event' object. By calling the 'stopPropagation' method of the event object, you can prevent bubbling.

丿*梦醉红颜 2024-08-03 13:53:26

我遇到了这种对我有用的替代语法;

$("a").bind("click", function(e) {e.stopPropagation();});

I've come across this alternative syntax which worked for me;

$("a").bind("click", function(e) {e.stopPropagation();});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文