日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

前端笔记-利用thymeleaf隐藏显示input及label

發布時間:2025/3/15 HTML 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端笔记-利用thymeleaf隐藏显示input及label 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先來看看效果:

這里有一個add.html,添加,修改都使用這個文件,當點擊添加后:

add.html被構造成這樣(點擊添加后):

當點擊編輯后:

對應的前端源碼如下:

<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head><link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css" /><link rel="stylesheet" type="text/css" href="#" th:href="@{/bg/my.css}" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><meta name="description" content="" /><meta name="author" content="" /><title>考勤管理系統</title><!-- Bootstrap core CSS --><link href="asserts/css/bootstrap.min.css" th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}" rel="stylesheet" /> `<!-- Custom styles for this template --><link href="asserts/css/dashboard.css" th:href="@{/asserts/css/dashboard.css}" rel="stylesheet" /><style type="text/css">/* Chart.js */@-webkit-keyframes chartjs-render-animation {from {opacity: 0.99}to {opacity: 1}}@keyframes chartjs-render-animation {from {opacity: 0.99}to {opacity: 1}}.chartjs-render-monitor {-webkit-animation: chartjs-render-animation 0.001s;animation: chartjs-render-animation 0.001s;}</style> </head><body><div class="container-fluid"><div class="row"><!-- 引入sidebar --><div th:replace="commons/bar::#sidebar(activeUri='super')"></div><main class="main ui container"><div class="ui grid"><div class="one wide column"></div><div class="fifteen wide column"><form th:action="@{/admin/add}" method="post"><input type="hidden" name="_method" value="put" th:if="${people!=null}"/><input type="hidden" name="id" th:if="${people!=null}" th:value="${people.id}"/><div class="form-group"><label>用戶名</label><input name="account" type="text" class="form-control" placeholder="root"th:value="${people!=null}?${people.id}" th:readonly="${people!=null} ? 'true':'false'" /></div><div class="form-group"><label>密碼</label><input name="password" type="password" class="form-control" placeholder="123456"th:value="${people!=null}?${people.pwd}" /></div><div class="form-group"><label>是否激活</label><br/><div class="form-check form-check-inline"><input class="form-check-input" type="radio" name="active" value="1"th:checked="${people!=null}?${people.active==1}" /><label class="form-check-label">是</label></div><div class="form-check form-check-inline"><input class="form-check-input" type="radio" name="active" value="0"th:checked="${people!=null}?${people.active==0}" /><label class="form-check-label">否</label></div></div><div class="form-group"><label th:style="${people==null} ? 'display: none' : ''">修改時間</label><input th:type="${people!=null} ? 'text' : 'hidden'" class="form-control" placeholder="2020/3/12 "th:value="${people!=null}?${#dates.format(people.modifyTime, 'yyyy-MM-dd hh:mm:ss')}" readonly="readonly" /></div><div class="form-group"><label th:style="${people==null} ? 'display: none' : ''">創建時間</label><input th:type="${people!=null} ? 'text' : 'hidden'" class="form-control" placeholder="2020/3/12"th:value="${people!=null}?${#dates.format(people.createTime, 'yyyy-MM-dd hh:mm:ss')}" readonly="readonly" /></div><button type="submit" class="btn btn-primary" th:text="${people!=null}?'修改':'添加'">添加</button><p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p></form></div></div></main></div> </div><script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js" th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script> <script type="text/javascript" src="asserts/js/popper.min.js" th:src="@{/webjars/popper.js/1.11.1/dist/popper.js}"></script> <script type="text/javascript" src="asserts/js/bootstrap.min.js" th:src="@{/webjars/bootstrap/4.0.0/js/bootstrap.js}"></script><script type="text/javascript" src="#" th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script></body></html>

首先要知道個知識點:

input隱藏使用type="hidden"

label隱藏使用display: none

這里可以通過后端是否發來了model,如果有model說明是編輯界面,如果沒有model說明是添加!

然后進行對應的顯示,隱藏即可:

?

總結

以上是生活随笔為你收集整理的前端笔记-利用thymeleaf隐藏显示input及label的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。