Bootstrap Collapse with multiple button and div

后端 未结 2 1959
情深已故
情深已故 2021-01-27 23:56

I have seen this example of collapse in w3school

    


  

        
相关标签:
2条回答
  • 2021-01-28 00:22

    You can use any accordion plugins to achieve this.

    If you want to go with a small piece of code, go with this:

    $('#btn1').click(function(){
      $('.collapse').hide();
      $('#demo').show();
    });
    $('#btn2').click(function(){
      $('.collapse').hide();
      $('#demo1').show();
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="container" ng-app="myApp" ng-controller="customersCtrl">
      <button type="button" class="btn btn-default" data-toggle="collapse" data-target="#demo" id="btn1" >Company Details</button>
      <button type="button" class="btn btn-default" data-toggle="collapse" data-target="#demo1" id="btn2">Commercial Details</button>
      <div id="demo" class="collapse" >
        1st div
      </div>
    
      <div id="demo1" class="collapse">
        2nd div
      </div>
    </div>

    0 讨论(0)
  • 2021-01-28 00:43

    It sounds like using bootstraps accordion would give you the desired effects: http://getbootstrap.com/javascript/#collapse-example-accordion

    It will allow you to collapse other divs when opening one, for instance.

    0 讨论(0)
提交回复
热议问题