Thymeleaf 获取对象属性作为JavaScript函数的参数分为以下两种情况: 传递数值 a rel=nofollow href=javascript:; th:onclick='changeStatus('+${user.id}+',1)' 启用/afunction changeStatus(id,status){alert(id+ +status);} 传
Thymeleaf 获取对象属性作为JavaScript函数的参数分为以下两种情况:
传递数值
<a rel="nofollow" href="javascript:;" th:onclick="'changeStatus('+${user.id}+',1)'" >启用</a>
function changeStatus(id,status){
alert(id+" "+status);
}
传递字符串
<a rel="nofollow" title="删除" href="javascript:;" th:onclick="changeName(1,[[${user.name}]])" >修改名字</a>
function changeName(id,name){
alert(id+" "+name);
}
综合
<a rel="nofollow" href="#!" th:onclick="updateUser([[${user.id}]],[[${user.name}]],[[${user.addr}]],[[${user.priority}]],[[${user.status}]])" >编辑</a>
function updateProvince(id,name,area,priority,status) {
alert(id+" "+name+" "+area+" "+priority+" "+status)
}
在JavaScript块中使用
<script type="text/javascript" th:inline="javascript">
let name= [[${user.name}]]
</script>