以下是代码段:
<div class="col-sm-4" id="tag-sidebar">
<div id="accordion">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">Collapsible Group 1</a><br>
<div id="collapse1" class=" collapse">
Lorem ipsum dolor .</div>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">Collapsible Group 1</a><br>
<div id="collapse2" class=" collapse ">
Lorem ipsum dolor sit amet, ut aliqui.</div>
</div>
<div id="tags-accordion">
<a data-toggle="collapse" data-parent="#tags-accordion" href="#ta_collapse1">Iesaukumi</a><br>
<div id="#ta_collapse1" class="collapse">
<?php foreach ($iesaukumi as $iesaukums): ?>
<a href="#" class="tag" data-value="1_<?php echo $iesaukums['id']; ?>"><?php echo $iesaukums['name']; ?></a>
<?php endforeach; ?>
</div>
</div>
</div>
和我几个小时试图理解的奇怪的事情是数据 - 父“手风琴”正在工作,而数据 - 父“标签 - 手风琴”不起作用。
“tags-accordion”是复制+粘贴。我检查没有PHP部分仍然相同。第一支手风琴有效但第二手风琴没有崩溃。
我确信有一些小愚蠢的错误,但是我花了一个小时才发现它没有成功。我重写了代码,但仍然是一些代码。我对这段代码很生气! Pleasr帮助我理解这个问题
更新
<div id="tags-accordion">
<a data-toggle="collapse" data-parent="#tags-accordion" href="#tacollapse1">Iesaukumi</a><br>
<div id="#tacollapse1" class="collapse">
<?php foreach ($iesaukumi as $iesaukums): ?>
<a href="#" class="tag" data-value="1_<?php echo $iesaukums['id']; ?>"><?php echo $iesaukums['name']; ?></a>
<?php endforeach; ?>
</div>
<?php $prevGroup = null;?>
<?php foreach ($tags as $row): ?>
<?php if($prevGroup != $row['grupa']):?>
<?php if(!is_null($prevGroup)):?>
</div>
<?php endif;?>
<a data-toggle="collapse" data-parent="#tags-accordion" href="#tacollapse<?php echo $row['grupa'];?>"><?php echo $row['grupa'];?></a><br>
<div id="#tacollapse<?php echo $row['grupa'];?>" class="collapse">
<?php $prevGroup = $row['grupa'];?>
<?php endif;?>
<a href="#" class="tag" data-value="2_<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a>
<?php endforeach; ?>
</div>
</div>
答案 0 :(得分:-1)
检查一下..
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="col-sm-4" id="tag-sidebar">
<p> part 1</p>
<div id="accordion">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">Collapsible Group 1</a><br>
<div id="collapse1" class=" collapse">Lorem ipsum dolor .</div>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">Collapsible Group 2</a><br>
<div id="collapse2" class=" collapse ">Lorem ipsum dolor sit amet, ut aliqui.</div>
<a data-toggle="collapse" data-parent="#accordion" href="#Iesaukumi1">Collapsible Group 2</a><br>
<div id="Iesaukumi1" class=" collapse ">Lorem ipsum dolor sit amet, ut aliqui.</div>
</div>
<p>part 2 </p>
<div id="tags-accordion">
<a data-toggle="collapse" data-parent="#tags-accordion" href="#Iesaukumi">PHP Iesaukumi 1</a><br>
<div id="Iesaukumi" class="collapse">PHP Code.</div>
<a data-toggle="collapse" data-parent="#tags-accordion" href="#collapse22">PHP Group 1</a><br>
<div id="collapse22" class="collapse">PHP Code.</div>
</div>
</div>
</div>
</body>
</html>