<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
$(document).ready(function() {
$('.accordion-header').click(function() {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).next().slideUp();
} else {
$('.accordion-header').removeClass('active');
$('.accordion-content').slideUp();
$(this).addClass('active');
$(this).next().slideDown();
}
});
});
<div class="accordion">
<div class="accordion-header">Header 1</div>
<div class="accordion-content">Content 1</div>
<div class="accordion-header">Header 2</div>
<div class="accordion-content">Content 2</div>
<div class="accordion-header">Header 3</div>
<div class="accordion-content">Content 3</div>
</div>
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com