我正在尝试构建一个应用程序,用户可以在右上角按下abutton(参见图像),隐藏一个div(主题)并显示另一个div(我可以添加新主题的表单)。
if(isset($actiefboardid)){
$toppic = $app->get_topics($actiefboardid);
if(count($toppic)>0){
foreach($toppic as $topic){
echo "<div class='user-block'>";
if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) {
echo '<img class="img-circle img-bordered-sm" src="/assets/images/profielfotos/'.$topic['klant_id']. '/' .$topic['foto'].'" />';
} else {
echo '<div class="fancyimg"><i class="img-circle img-bordered-sm fa fa-fw fa-user img-circle"></i></div>';
}
echo "<span class='username'><a href='https://tom.lbmedia.nl/boards/".$url[1]."/".$topic['url']."'>". $topic['topicnaam'] . "</a>
</span><span class='description'>
<span style='float:right;margin-left:5px;'>".implode($app->count_reactie($topic['id'])) ." reacties
</span>
<span style='float:right; color:lightgrey;' class='fa fa-comment'></span>
<span class='badge bg-red' style='border-radius: 5px;'>" . implode($app->boards($topic['board_id'])) . "
</span>
laatste reactie: " .$app->tijd_reactie($topic['id']) . " door " .$app->reactieDoor($topic['id'])."</div></span>
<hr></hr>
<p></p>
<form class='form-horizontal'>
<div class='form-group margin-bottom-none'>
</div>
</form>
";
}
} else {
echo "Er zijn nog geen topics bij dit board";
}
这是显示主题的代码。现在我需要实现上面描述的按钮。
答案 0 :(得分:0)
您可以在触发点击事件时显示/隐藏表单和主题。 所以第一次,显示主题并隐藏表单,然后单击,切换它们
答案 1 :(得分:0)
从高层来看:
var showTable = true
){display: hidden}
添加到HTML标记的CSS类<div
&gt; 虽然这可以在纯Javascript中完成,但使用诸如jQuery或Angular之类的库将使您更轻松地完成此任务。
jQuery示例:
// In your CSS file
.hidden {
display: hidden;
}
// In your JS File
var showTable = true;
$('#myButton').click(function() {
showTable = !showTable;
if (showTable) {
$('#div1').addClass('hidden');
$('#div2').removeClass('hidden');
else {
$('#div2').addClass('hidden');
$('#div1').removeClass('hidden');
}