gpt4 book ai didi

php - 关闭 'accordian'
但强制返回 'top'

转载 作者:行者123 更新时间:2023-11-28 03:49:03 24 4
gpt4 key购买 nike

我在 PHP while 循环中嵌入了一个“ Accordion ”...PHP 从数据库中提取数据以填充面板——这部分工作正常。每个面板都按照所述的标签链接加载和打开……到此为止一切正常。

但是,当单击关闭面板的调用链接时,页面会完全下降到“html 正文”的底部,而不是返回到“html 正文”的顶部并显示完整的“ Accordion ”如可用.. 任何建议表示赞赏。谢谢。

<div id="container">
<?php
// title heading
$seek_title=mysql_query("select title from lessons where id = $lesson_id");
$the_title=mysql_fetch_array($seek_title);
$lesson_title= $the_title[0];
echo '<h3>'.$lesson_title.'</h3>';
// count pages
$count_pages= mysql_query("SELECT * FROM pages WHERE lesson_id = '$lesson_id'") or die(mysql_error());
$page_count= mysql_num_rows($count_pages);?>
<a name="top"></a>
<div class="panel-group" id="accordion">
<?php
for ($x=1; $x <= $page_count; $x++){
//SQL to pull title and content for the current page
$result = mysql_query("SELECT title, body FROM pages WHERE lesson_id = '$lesson_id' AND position = '$x' ") or die(mysql_error());
$row = mysql_fetch_row($result);
$title = $row[0];
$content = $row[1];?>
<div class="panel panel-default" >
<div class="panel-heading">
<h3 class="panel-title"><strong>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $x; ?>"><span class='glyphicon glyphicon-chevron-down'></span>&nbsp;&nbsp;<?php echo $title; ?></a></strong></h3>
</div>
<div id="collapse<?php echo $x; ?>" class="panel-collapse collapse">
<div class="panel-body" ><?php echo $content; ?>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $x; ?>" ><span class='glyphicon glyphicon-chevron-up'></span>&nbsp;&nbsp;Close</a><br/>
</div>
</div>
</div>
<?php } ?>
</div>
</div>

最佳答案

将关闭标签更改为以下内容:

<a data-toggle="collapse" data-parent="#accordion" href="#accordion"><span class='glyphicon glyphicon-chevron-up'></span>&nbsp;&nbsp;Close</a><br/>

注意 href。它应该从现在开始到顶部。

关于php - 关闭 'accordian' <div> 但强制返回 'top',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43822477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com