jQuery Accordion: links don't work

后端 未结 9 574
终归单人心
终归单人心 2020-12-06 08:44

I\'m working on a page using jQuery\'s accordion UI element. I modeled my HTML on that example, except that inside the

  • elements, I have some unordere
  • 9条回答
    •  星月不相逢
      2020-12-06 08:52

      I had this exact same problem and could not find an answer anywhere. In fact, a couple sources said it just couldn't be done.

      Upon further playing, I did find a working solution. May not be great, but it works like a charm.

      First, just make sure the links you want to be clickable, and immune to the accordion controls, is easily identifiable. I had a class on mine.

       $('.stats a').click(function(){
      expander.accordion('disable');
      window.open($(this).attr('href'));
      
      setTimeout ( function() {
        expander.accordion('enable');
      }, 250 );
      

      });

      Essentially, this listens for when a link inside the accordion header is clicked. When it is, the accordion is temporarily disabled, keeping it from firing as normal. The link is then opened, in this case, in a new window but you could use document.location as well

      If we re-enabled the accordion immediately, it will still fire and toggle the accordion. I found that a super-short timeout provides enough delay.

      Hope this helps someone!

    提交回复
    热议问题