【问题标题】:Bootstrap accordion - Dont close other accordion unless user click to closeBootstrap 手风琴 - 除非用户单击关闭,否则不要关闭其他手风琴
【发布时间】:2020-04-08 16:47:26
【问题描述】:

在引导手风琴示例下方使用。手风琴的功能很好。

当用户展开第一个手风琴并单击第二个手风琴时。第一手风琴不应该关闭。但是,当用户单击第二个手风琴时,它会关闭第一个手风琴。

手风琴的展开/折叠必须手动打开/关闭。

不确定是否需要更新 JS 或 CSS 来解决此问题。请指导我找到解决方案。

谢谢

$('.collapse.show').each(function(){
      $(this).prev('.card-header').find('.fa').addClass('fa-minus').removeClass('fa-plus');
    });
    
    // Toggle plus minus icon on show hide of collapse element
    $('.collapse').on('show.bs.collapse', function(){
      $(this).prev('.card-header').find('.fa').removeClass('fa-plus').addClass('fa-minus');
    }).on('hide.bs.collapse', function(){
      $(this).prev('.card-header').find('.fa').removeClass('fa-minus').addClass('fa-plus');
    });
<div class="accordion" id="accordionExample">
    <div class="card">
        <div class="card-header" id="headingOne">
            <h2 class="mb-0"><button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne"><i class="fa fa-plus"></i> What is HTML?</button></h2>
        </div>
        <div class="collapse" id="collapseOne" aria-labelledby="headingOne" data-parent="#accordionExample">
            <div class="card-body">
                <p>HTML stands for HyperText Markup Language. HTML is the standard markup language for describing the structure of web pages. <a href="https://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="card-header" id="headingTwo">
            <h2 class="mb-0"><button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseTwo"><i class="fa fa-plus"></i> What is Bootstrap?</button></h2>
        </div>
        <div class="collapse" id="collapseTwo" aria-labelledby="headingTwo" data-parent="#accordionExample">
            <div class="card-body">
                <p>Bootstrap is a sleek, intuitive, and powerful front-end framework for faster and easier web development. It is a collection of CSS and HTML conventions. <a href="https://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

    标签: javascript jquery twitter-bootstrap


    【解决方案1】:

    为了防止第一个手风琴在单击第二个手风琴时关闭,您只需删除代码 sn-p 的 HTML 部分中的data-parentattribute。

    <div class="accordion" id="accordionExample">
        <div class="card">
            <div class="card-header" id="headingOne">
                <h2 class="mb-0"><button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne"><i class="fa fa-plus"></i> What is HTML?</button></h2>
            </div>
            <div class="collapse" id="collapseOne" aria-labelledby="headingOne">
                <div class="card-body">
                    <p>HTML stands for HyperText Markup Language. HTML is the standard markup language for describing the structure of web pages. <a href="https://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header" id="headingTwo">
                <h2 class="mb-0"><button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseTwo"><i class="fa fa-plus"></i> What is Bootstrap?</button></h2>
            </div>
            <div class="collapse" id="collapseTwo" aria-labelledby="headingTwo">
                <div class="card-body">
                    <p>Bootstrap is a sleek, intuitive, and powerful front-end framework for faster and easier web development. It is a collection of CSS and HTML conventions. <a href="https://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
                </div>
            </div>
        </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      相关资源
      最近更新 更多