I have a bootstrap accordion setup and working fine.
I need to have links on external pages which will:
A) Take you to the specified panel within the accordion
B) Open the specified panel
The link structure needs to be in this format (example):
Page.html#collapseTwo
(the 'collapseTwo' will change, of course, depending on the panel)
The HTML:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container"
id="page_container">
<div id="accordion_search_bar_container">
<input type="search"
id="accordion_search_bar"
placeholder="Search"/>
</div>
<div class="panel-group"
id="accordion"
role="tablist"
aria-multiselectable="true">
<div class="panel panel-success"
id="collapseOne_container">
<div class="panel-heading"
role="tab"
id="headingOne">
<h4 class="panel-title">
<a role="button"
data-toggle="collapse"
data-parent="#accordion"
href="#collapseOne"
aria-expanded="true"
aria-controls="collapseOne">
One
</a>
</h4>
</div>
<div id="collapseOne"
class="panel-collapse collapse in"
role="tabpanel"
aria-labelledby="headingOne">
<div class="panel-body">
<p>Pellentesque convallis dolor</p>
<p>Enim at tincidunt magna dapibus vitae</p>
</div>
</div>
</div>
<div class="panel panel-primary"
id="collapseTwo_Container">
<div class="panel-heading"
role="tab"
id="headingTwo">
<h4 class="panel-title">
<a class="collapsed"
role="button"
data-toggle="collapse"
data-parent="#accordion"
href="#collapseTwo"
aria-expanded="false"
aria-controls="collapseTwo">
Two
</a>
</h4>
</div>
<div id="collapseTwo"
class="panel-collapse collapse in"
role="tabpanel"
aria-labelledby="headingTwo">
<div class="panel-body">
<p>Vestibulum in laoreet nisi</p>
<p>Sit amet placerat massa</p>
</div>
</div>
</div>
<div class="panel panel-danger"
id="collapseThree_Container">
<div class="panel-heading"
role="tab"
id="headingThree">
<h4 class="panel-title">
<a class="collapsed"
role="button"
data-toggle="collapse"
data-parent="#accordion"
href="#collapseThree"
aria-expanded="false"
aria-controls="collapseThree">
Three
</a>
</h4>
</div>
<div id="collapseThree"
class="panel-collapse collapse in"
role="tabpanel"
aria-labelledby="headingThree">
<div class="panel-body">
<p>Curabitur sem eros tempor sit</p>
<p>Amet nunc eget, gravida mollis</p>
</div>
</div>
</div>
</div>
</div>
The JS:
(function() {
var searchTerm, panelContainerId;
// Create a new contains that is case insensitive
$.expr[':'].containsCaseInsensitive = function(n, i, m) {
return jQuery(n).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
$('#accordion_search_bar').on('change keyup paste click', function() {
searchTerm = $(this).val();
$('#accordion > .panel').each(function() {
panelContainerId = '#' + $(this).attr('id');
$(panelContainerId + ':not(:containsCaseInsensitive(' + searchTerm + '))').hide();
$(panelContainerId + ':containsCaseInsensitive(' + searchTerm + ')').show();
});
});
}());
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…