网上大多帖子是这么写的
onclick调javascript函数时,不能直接使用onclick=“editUser(${prod.id})”,这样会报错,需要修改成如下的格式。
|
1
2
3
4
5
6
7
8
9
10
11
|
<a href="#editModal" role="button" data-toggle="modal" th:onclick="\'javascript:editUser(\'+${prod.id}+\');\'">修改</a>
<script>function editUser(id){ $.get("/projectName/user/edit",{objectid:id},function(data) {
$("#frm_container1").html(data);
});
}
</script> |
但是这种方式对于我的问题并不是很适用,按照这种方式,改过之后,前端依旧报错
取不到传递的字符串,大概就是这个被传递的字符串木有被定义 is not define
所以,对于thymeleaf+bootstrap,onclick传递字符串参数时,应该是这样的
|
1
|
<a href="#editModal" role="button" data-toggle="modal" th:onclick="\'javascript:editUser(\\'\'+${prod.id}+\'\\');\'">修改</a>
|