Accordion with a link to external resource

梦想与她 提交于 2019-12-11 04:02:56

问题


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.

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

Example code:

<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/

is it at all possible to implement?


回答1:


Forked to http://jsfiddle.net/ZPLff/

changes :

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

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

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



来源:https://stackoverflow.com/questions/13681265/accordion-with-a-link-to-external-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!