我在 accordion 工作,并打开一个面板上点击另一个链接<div id="open">Open It</div>
.但它不能顺利打开.然而,当我打开点击卡头它的打开非常顺利.如何实现这一点?
超文本标记语言
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</button>
</h5>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div id="open">Open It</div>
</div>
函数
<script>
$(document).on('click', '#open', function () {
$('#collapseOne').toggleClass('show')
})
</script>
2条答案
按热度按时间3phpmpom1#
您可以使用. slideToggle()
aemubtdh2#
从你的类/数据来看-看起来你在使用bootstrap 4 accordion。
在使用bootstrap等库时,谨慎的做法是使用所提供的API,在本例中:
如果您只想显示而不想切换,还有其他选项,如
.collapse("show")
。更新了 Bootstrap :
x一个一个一个一个x一个一个二个x