gpt4 book ai didi

javascript - 从 URL 展开特定 Accordion

转载 作者:行者123 更新时间:2023-11-30 16:54:19 26 4
gpt4 key购买 nike

如果我使用地址“www.xxxxxx.com/test.html#chgd”,第二个 Accordion 应该展开。

我使用了这个网站的源代码'Bootstrap 3 expand accordion from URL ' 但它在这种情况下不起作用。

根据源码扩展第二个基于URL的 Accordion ,不知道是什么问题?

<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link href="C:\Users\h\Desktop\test\bootstrap-theme.css" rel="stylesheet"/>
<link href="C:\Users\h\Desktop\test\bootstrap.css" rel="stylesheet"/>

<script src="C:\Users\h\Desktop\test\jquery-1.11.2.min.js"></script>
<script src="C:\Users\h\Desktop\test\bootstrap.min.js"></script>
<script>
var url = document.location.toString();
if (url.match('#')) {
$('#' + url.split('#')[1]).addClass('in');
}
</script>
</head>

<body>
<div id="accordion" class="accordion-group">
<div class="panel">
<h4 id="cs" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#cs_c">Child
Survival: Boosting Immunity and Managing Diarrhoea</a></h4>
<div id="cs_c" class="accordion-collapse collapse in">
<p>...</p>
</div>

<h4 id="chgd" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#chgd_c">Child
Health, Growth and Development: Preventing Mental Impairment with Iodine and Iron</a></h4>
<div id="chgd_c" class="accordion-collapse collapse">
<p>...</p>
</div>

<h4 id="wmnh" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#wmnh_c">Women’s
and Newborn Survival and Health: Iron Supplementation and Food Fortification</a></h4>
<div id="wmnh_c" class="accordion-collapse collapse">
<p>...</p>
</div>
</div>
</div>
</body>
</html>

最佳答案

试试这个:

    <script>

jQuery(document).ready(function() {
var url = document.location.toString();
if ( url.match('#') ) {
var hash = url.split('#')[1];

// collapse the expanded panel
$('#accordion .accordion-collapse').removeClass('in');

// expand the requested panel
$('#' + hash + '_c').addClass('in');
}
});
</script>

关于javascript - 从 URL 展开特定 Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29987154/

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