jQuery Accordion: links don't work

后端 未结 9 548
终归单人心
终归单人心 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:50

      here is a really simple solution

      http://www.designerstalk.com/forums/help-me/41297-jquery-accordion-embedding-links-help-needed.html

      0 讨论(0)
    • 2020-12-06 08:51

      Try adding an inline onlick that prevents event bubbling:

      ...
      <a href='#' onclick="event.stopPropagation()" class="accordion-label">A Group of Links</a>
      ...
      

      Or a domready event like so:

      $(".toggle-title a").click(function(event){ event.stopPropagation()})
      

      However the latter didn't work for me even though code wise it makes sense, jQuery executes the click! Anyone that can explain that to me feel free, I come from MooTools and Google Closure background which has addEvent functions.

      0 讨论(0)
    • 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!

      0 讨论(0)
    • 2020-12-06 08:52

      AlwaysOpen should be true.

      0 讨论(0)
    • 2020-12-06 08:55

      As my answer to your other question says:

       navigation: true
      

      Should be set in your option list.

      0 讨论(0)
    • 2020-12-06 09:04

      Here is a possible alternative script for anyone still experiencing this issue: http://twostepmedia.co.uk/notes/development/jquery-accordion/

      0 讨论(0)
    提交回复
    热议问题