版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yhflyl/article/details/83687163
动态加载下拉框并设置选中
<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=\''+@{/statics/images/backgroup.jpg}+'\''">