Linking to a section of an Accordion from another page

后端 未结 4 2055
借酒劲吻你
借酒劲吻你 2020-12-14 17:51

I\'m using twitter-Bootstrap 2.04, and I\'m using the latest jQuery. I\'m trying to make a link that will go from one page to the page containing this accordion, and then ac

相关标签:
4条回答
  • 2020-12-14 18:15

    You can use the position of the accordion section. The following link opens the third accordion section on a twitter bootstrap (wordpress) accordion.

    Link Example: http://www.zfp-bauwesen.de/leistungen/ubersicht#3

    Javscript Code:

    $( document ).ready(function() {
    
     if (window.location.hash) {
       var AccordionSectionNumber = window.location.hash.substring(1);
       AccordionBodyID = $(".accordion .accordion-group:nth-of-type(" + AccordionSectionNumber + ") .accordion-heading a").attr('href')
          if (! (typeof AccordionBodyID === "undefined")) {
            $(AccordionBodyID).collapse('show');
            return true;
          }
        }
    
    });
    
    0 讨论(0)
  • 2020-12-14 18:23

    Thanks for your help.
    I added functionality so that the code can open Accordions WITHIN Accordions:

    $(document).ready(function () {
      if (location.hash){
        $(location.hash).collapse('show');
        $(location.hash).parents('.accordion-body').collapse('show');
      }
    });
    
    0 讨论(0)
  • 2020-12-14 18:24

    Yes, you will need to manually activate it on page load. Something like the following should work:

    $(document).ready(function () {
      location.hash && $(location.hash + '.collapse').collapse('show');
    });
    

    Also, as @SaadImran pointed out, this assumes that you link to the collapsible element id (eg., #collapseTwo) rather than the name in the anchor (eg., #Alink2).

    0 讨论(0)
  • 2020-12-14 18:29

    Have you tried this:

    <a href="page.html#Alink2">Link to some interesting stuff</a>
    
    0 讨论(0)
提交回复
热议问题