使用Thymeleaf变量给onclick属性赋值
在使用thymeleaf渲染页面时,遇到如下情况:
1 | <button onclick="submit('publish');">提交</button> |
submit
函数的参数会根据后端参数的不同而动态改变,Google搜索到了一些类似问题,记录一下解决方法。
已经测试可用的:
1 | th:onclick="'alert(\'' + ${myVar} + '\');'" |
还未测试:
1 | <button th:onclick="'javascript:upload(' + ${gallery} + ')'"></button> |
如果觉得我的文章对您有帮助,请随意打赏。