手风琴与外部资源的链接 [英] Accordion with a link to external resource

查看:100
本文介绍了手风琴与外部资源的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使可折叠的带有整个标题DIV的手风琴,其中还包括一个不影响手风琴状态,而是在新标签页/窗口中打开外部链接的链接。

I am trying to have an accordion with whole header DIV clickable which also includes a link which does not influence accordion status but instead open an external link in new a tab/windows.

但是,如果这样做,标题将捕获链接上的click事件,并且仅切换手风琴状态。

but if I do this, header is capturing click event on my link and it toggles accordion status only.

示例代码:

<div class="accordion" id="accordion2">
  <div class="accordion-group">
    <div class="accordion-heading accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
      <a href="http://www.google.com" target="_blank">
        Collapsible Group Item #1
      </a><br />
      whole heder is<br />
      clickable<br />
    </div>
    <div id="collapseOne" class="accordion-body collapse in">
      <div class="accordion-inner">
        Anim pariatur cliche...
      </div>
    </div>
  </div>
</div>

http://jsfiddle.net/LUzwP/6/

是否有可能实施?

推荐答案

分叉到 http://jsfiddle.net/ZPLff /

更改:

<a href="http://www.google.com" target="_blank" id="google">

$("#google").click(function(e) {
    e.stopPropagation();
});​

原因: data-toggle = collapse (在可折叠data-api中)调用 e.preventDefault()在其 .on.click()处理程序中,因此您必须防止这种情况

reason : data-toggle="collapse" (in collapsible data-api) calls e.preventDefault() in its .on.click()-handler, so you have to prevent this

这篇关于手风琴与外部资源的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆