學做網(wǎng)站網(wǎng)百度網(wǎng)訊科技有限公司官網(wǎng)
需求背景:在html中,當滿足什么條件時,顯示什么html元素,否則不顯示什么元素
舉個簡單的th:block使用,三個按鈕1和3為true,2是false,那么2中被th:block包含的代碼段則不顯示,效果如下圖<th:block th:if='${1==1}'><button class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"></i> 新增1顯示</button></th:block><th:block th:if='${1!=1}'><button class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"></i> 新增2不顯示</button></th:block><th:block th:if='${1==1}'><button class="btn btn-default" data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"></i> 新增3顯示</button></th:block>