单击按钮使面板关闭,但是当我再次单击按钮时,面板将无法打开。
我已经检查以确保没有遗漏任何结束标记,并发现一切正常。
不确定我错过了什么。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#myPanel" aria-expanded="false" aria-controls="myPanel">
Collapse
</button>
<div id="VIDContactInfoWrapper" style="border:1px solid black;">
<div class="panel panel-default" style="height:inherit;">
<div class="panel-heading" style="padding: 5px 5px !important">Information</div>
<div class="panel-body" id="myPanel" style="padding-top:0;padding-bottom:0;height:300px; background-color:hotpink;">
<div class="row">
<div class="col-md-12">
<div class="row">
<div id="VIContactInfo" class="col-md-6" style="background: white;"></div>
<div id="VIAddressInfo" class="col-md-6" style="background: white;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
实际上,您必须将面板主体包裹在可折叠的div中。 https://getbootstrap.com/docs/3.3/javascript/#collapse
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#myPanel" aria-expanded="false" aria-controls="myPanel">
Collapse
</button>
<div id="VIDContactInfoWrapper" style="border:1px solid black;">
<div class="panel panel-default" style="height:inherit;">
<div class="panel-heading" style="padding: 5px 5px !important">Information</div>
<div id="myPanel" class="panel-collapse collapse in">
<div class="panel-body" style="padding-top:0;padding-bottom:0;height:300px; background-color:hotpink;">
<div class="row">
<div class="col-md-12">
<div class="row">
<div id="VIContactInfo" class="col-md-6" style="background: white;"></div>
<div id="VIAddressInfo" class="col-md-6" style="background: white;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
您提供的代码可以正常工作。问题在于您正在使用内联样式定义panel-body
元素的高度,当您使用Bootstrap切换时,该样式会被覆盖。要解决此问题,只需允许panel-body
中的内容定义高度,或者改为在外部CSS中定义高度:
.panel-body {
padding-top:0;
padding-bottom:0;
height:300px;
background-color:hotpink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#myPanel" aria-expanded="false" aria-controls="myPanel">
Collapse
</button>
<div id="VIDContactInfoWrapper" style="border:1px solid black;">
<div class="panel panel-default" style="height:inherit;">
<div class="panel-heading" style="padding: 5px 5px !important">Information</div>
<div class="panel-body" id="myPanel">
<div class="row">
<div class="col-md-12">
<div class="row">
<div id="VIContactInfo" class="col-md-6" style="background: white;"></div>
<div id="VIAddressInfo" class="col-md-6" style="background: white;"></div>
</div>
</div>
</div>
</div>
</div>
</div>