我想在PHP for循环中使用bootstrap手风琴。但它并没有崩溃。我不确定我做错了什么。
这是我的代码。
<?php
$row_count = 1;
for ($x = 0; $x < 5; $x++) {
echo $row_count ;
?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1<?php echo $row_count; ?>">Collapsible Group 1</a>
</h4>
</div>
<div id="collapse1<?php echo $row_count ?>" class="panel-collapse collapse ">
<div class="panel-body">Lorem.</div>
</div>
</div>
</div>
<?php
$row_count ++;
}
?>
答案 0 :(得分:0)
重写您的代码如下: -
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php
$row_count = 1;
for ($x = 0; $x < 5; $x++) { ?>
<div class="panel panel-default" >
<div class="panel-heading" role="tab" id="heading<?php echo $row_count ?>">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $row_count; ?>" aria-expanded="false"">Collapsible Group <?php echo $row_count?></a>
</h4>
</div>
<div id="collapse<?php echo $row_count; ?>" class="panel-collapse collapse " role="tabpanel" aria-labelledby="heading<?php echo $row_count; ?>">
<div class="panel-body">Lorem.</div>
</div>
</div>
<?php $row_count++; } ?>
</div>
答案 1 :(得分:0)
试试这个
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php
$row_count = 1;
for ($x = 0; $x < 5; $x++) {
?>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne<?=$row_count?>">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne<?=$row_count?>" aria-expanded="false" aria-controls="collapseOne<?=$row_count?>">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne<?=$row_count?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne<?=$row_count?>">
<div class="panel-body">
Lorem
</div>
</div>
</div>
<?php
$row_count ++;
}
?>
</div>