【发布时间】:2019-09-07 03:32:52
【问题描述】:
我一直在试图弄清楚如何通过 th:onclick 按钮将 url 传递给 spring 控制器方法。我已经尝试了许多不同的变体,但无法弄清楚我应该拥有多少 ' 或者我是否正确地逃避了事情。有人可以解释为什么这不起作用/使用 location.href 的正确方法是什么?
目前这是错误:无法解析为表达式:“'window.location.href=\'/removeContact''”
谢谢!!
<button type="button" th:onclick="'window.location.href=\'/removeContact''" name="removeContact" th:value="${stat.index}" class="btn btn-danger trashContact"><span class="fa fa-trash"></span></button>
【问题讨论】:
-
你不应该使用锚点吗?
-
您将语句包装在 " 和 ' 中。删除 '。只需使用
th:onclick="window.location.href='/removeContact'"
标签: javascript spring-boot thymeleaf