欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

thymeleaf之from相关

程序员文章站 2022-05-01 23:13:14
...

动态加载下拉框并设置选中

<select name="interest" lay-filter="aihao" id="gameMapUrl">
	<option value=""></option>
	<option th:each="mapList : ${mapLists}" th:value="${mapList.mapUrl}" th:text="${mapList.mapInfo}" th:selected="${mapList.mapUrl eq game.gameMapUrl}"></option>
</select>

单选按钮设置选中

<input type="radio" name="gameType" value="0" title="个人游戏" th:field="*{game.gameType}">
<input type="radio" name="gameType" value="1" title="团队游戏" th:field="*{game.gameType}">

js中使用thymeleaf变量

<script type="text/javascript" th:inline="javascript">
    let people_sum = [[${game.gameSumPeople}]] ? [[${game.gameSumPeople}]] : 0;
    let team_sum = [[${game.gameSumTeam}]] ? [[${game.gameSumTeam}]] : 0;
</script>

设置dom中的data-id这类属性

<div class="operator_btn">
	<button class="layui-btn layui-btn-warm layui-btn-sm game_edit_btn"  th:attr="data-id=${gameList.gameId}">编辑</button>
	<button class="layui-btn layui-btn-sm game_del_btn" th:attr="data-id=${gameList.gameId}">删除</button>
</div>

图片加载失败后的处理

<img th:src="${gameList.gamePic}" alt="" class="game_pic" th:onerror="'this.src=\''[email protected]{/statics/images/backgroup.jpg}+'\''">
相关标签: thymeleaf