今天在写代码,有个需求,就是在jquery拼接的html字符串中使用thmeleaf模板进行判断
使用th:if可是没有效果,不知道怎么回事,有没有大神指教一下,是不是自愿引入的错误
如何正确引入资源?
js引入
<script th:src="@{/jquery-3.4.1.js}" src="../static/jquery-3.4.1.js"></script>
<script th:inline="javascript" type="text/javascript"><script th:src="@{/jquery-3.4.1.js}" src="../static/jquery-3.4.1.js"></script>
<script th:inline="javascript" type="text/javascript">
jquery代码
$.ajax({
url: "/user/aulist",
type: "get",
dataType: "json",
success: function (json) {
console.log(json);
for (var i = 0; i < json.length; i++) {
html += "<div class=\"c\" >\n" +
" <div class=\"con\">\n" +
" <label style=\"color: black;font-weight: bold\">用户名 : <span>" + json[i].username + "</span> </label><br>\n" +
" <label style=\"color: black;font-weight: bold\">注册时间 :\n" +
" <span th:text=\"${#dates.format(json[i].editTime,'yyyy-MM-dd HH:mm:ss')}\">" + new Date(json[i].registerTime).toLocaleString().fontcolor('red') + "</span> \n" +
" </label>\n" +
" <label style=\"color: black;font-weight: bold\">状态 : <span>" + json[i].status + "</span> </label>\n" +
" <div class=\"con1\">\n" +
" <a id=\"userDelete\" href=\"/user/delete/" + json[i].id + "\" th:href=\"@{/user/delete/{id}(id=${" + json[i].id + "})}\">\n" +
" <button style=\"color: red\">删除</button>\n" +
" </a>\n" +
" <a id='userLock' href=\"/user/lock/" + json[i].id + "/"+ 0 + "\"><button>锁定</button></if>\n" +
" <a id='userUnlock' href=\"/user/lock/" + json[i].id + "/"+ 1 + "\"><button>解锁</button></if>\n" +
" </div>" +
" </div>\n" +
" </div>";
}
$("#content").html(html);
$("#userM div").addClass("active");
$("#welcomeM div").removeClass("active");
$("#articleM div").removeClass("active");
html = "";
}
});
希望能在显示状态前判断一下状态,然后显示文字,而不是数字