gpt4 book ai didi

jquery - 深层链接并打开 Accordion 项目

转载 作者:行者123 更新时间:2023-12-01 01:43:46 24 4
gpt4 key购买 nike

我正在尝试向下面的代码添加深层链接,以便我可以直接链接到 Accordion 项目,并在我在地址栏中输入正确的 URL 时打开它:

这是我的工作 Accordion ,没有深层链接:

$('.responsive-accordion').each(function() {

// Set Expand/Collapse Icons
$('.responsive-accordion-minus', this).hide();

// Hide panels
$('.responsive-accordion-panel', this).hide();

// Bind the click event handler
$('.responsive-accordion-head', this).click(function(e) {
// Get elements
var thisAccordion = $(this).parent().parent(),
thisHead = $(this),
thisPlus = thisHead.find('.responsive-accordion-plus'),
thisMinus = thisHead.find('.responsive-accordion-minus'),
thisPanel = thisHead.siblings('.responsive-accordion-panel');

// Reset all plus/mins symbols on all headers
thisAccordion.find('.responsive-accordion-plus').show();
thisAccordion.find('.responsive-accordion-minus').hide();

// Reset all head/panels active statuses except for current
thisAccordion.find('.responsive-accordion-head').not(this).removeClass('active');
thisAccordion.find('.responsive-accordion-panel').not(this).removeClass('active').slideUp();

// Toggle current head/panel active statuses
if (thisHead.hasClass('active')) {
thisHead.removeClass('active');
thisPlus.show();
thisMinus.hide();
thisPanel.removeClass('active').slideUp();
} else {
thisHead.addClass('active');
thisPlus.hide();
thisMinus.show();
thisPanel.addClass('active').slideDown();
}
});
});

我一直在尝试集成这段代码来启动深度链接,但它不起作用:

var active = 1;
var hash = document.location.hash;

if (hash.length > 0) {
var section = $("#deep-link").find("> li" + hash);
if (section.length) {
active = section.index();
}
thisPanel.addClass('active').slideDown();
}

HTML 是一个简单的 UL:

<ul class="responsive-accordion responsive-accordion-default bm-larger" id="deep-link">
<li id="item-0">
<div class="responsive-accordion-head">
Heading Here
</div>
<div class="responsive-accordion-panel">
Content here
</div>
</li>
</ul>

最佳答案

我认为您的函数中没有设置 thisPanel 变量。这应该适合你。

var active = 1;
var hash = document.location.hash;

if (hash.length > 0) {
var section = $("#deep-link").children("li" + hash);
var thisPanel = section.children(".responsive-accordion-panel");
if (section.length) {
active = section.index();
}
thisPanel.addClass('active').slideDown();
}

关于jquery - 深层链接并打开 Accordion 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31727657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com