0

我有一个与给定相同的标记、CSS 和 jquery 的手风琴。我无法建立外部锚链接(同一页面和其他页面)来触发打开特定面板。手风琴来自模板。

HTML

<!-- Accordions -->
<h1 class="h-margin">Accordions</h1>
<div class="accordion-trigger">Categories</div>     
<div class="accordion-container" data-panel="0">
    Pellentesque habitant 
</div>     

<div class="accordion-trigger">Categories</div> 
<div class="accordion-container" data-panel="1">
    Pellentesque habitant morbi 
</div>

<div class="accordion-trigger">Categories</div>         
<div class="accordion-container" data-panel="2">
    Pellentesque habitant morbi tris
</div>
<!-- ENDS Accordions -->

<a href="#">Open Section 1</a>

<a href="#">Open Section 2</a>

<a href="#">Open Section 3</a>

JavaScript

// Accordion box
$('.accordion-container').hide(); 
$('.accordion-trigger:first').addClass('active').next().show();
$('.accordion-trigger').click(function(){
    if( $(this).next().is(':hidden') ) { 
        $('.accordion-trigger').removeClass('active').next().slideUp();
        $(this).toggleClass('active').next().slideDown();
    }
    return false;
});
4

1 回答 1

0

它将帮助您:

 // open content that matches the hash
 var hash = window.location.hash;
 var thash = hash.substring(hash.lastIndexOf('#'), hash.length);
 $('.accordion').find('a[href*='+ thash + ']').closest('h3').trigger('click');
于 2013-10-17T10:20:13.290 回答