最近做Springboot的项目,在使用Thymeleaf模板时使用了th:onclick属性来调用JavaScript方法,其中涉及到ajax传入UUID到后台异步更新数据的功能。有以下几种写法:
1.涉及到转义符\’
<button class=“btn” th:οnclick="‘audit(\’’ + ${items.id} + ’ \’ );’">通过审核 通过
2.不需要转义符
<button class=“btn” th:οnclick="‘audit(’ + ${items.id} + ‘);’">通过审核
3.不需要单引号
<button th:οnclick="|audit(${items.id} )|">通过审核
4.thmeleaf 3.0以后版本
<button class=“btn” th:οnclick=“audit([[${items.id}]]);”>通过审核