首页 > 解决方案 > 如何通过按下按钮来替换 div 的内容

问题描述

我想在导航栏下方的容器中使用 th:insert 。每个按钮都会插入不同的代码。我知道有一个 th:if 但我不知道如何使用它来检查按钮是否被按下。对于这个问题,也许有比使用 th:insert 和 th:if 更好的解决方案?

我只是想更改容器的内容而不是重新加载到另一个页面。我已经准备好要插入页面的 html 文件。我正在使用 Spring Boot、Spring MVC、Thymeleaf

导航条码:

<nav class="navbar navbar-custom" aria-label="Desktop Navigation">
    <div class="container">
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="link">Add User</a></li>
                <li><a href="link">Users List</a></li>
            </ul>
        </div>
    </div>
</nav>

容器代码:

<div class="row">
  <div class="col-sm-12">
    <th:block th:if="(What I should insert here?)">
       <div th:insert="fragments/panelFragments :: addUserFragment" />
    </th:block>
    <th:block th:if="(What I should insert here?)">
       <div th:insert="fragments/panelFragments :: usersListFragment" />
    </th:block>
  </div>
</div>

标签: javahtmlspringspring-mvcthymeleaf

解决方案


推荐阅读