【问题标题】:How to change th:attr to th:onclick in Thymeleaf如何在 Thymeleaf 中将 th:attr 更改为 th:onclick
【发布时间】:2021-08-05 11:49:15
【问题描述】:

当我使用属性th:attr 时,一切正常。

但是当我想在没有th:attr 的情况下使用th:onclick 时,出现错误。 在没有th:attr 的情况下,我需要做什么才能使其正常运行?

<button th:each="user : ${users}"
        th:if="(${user.id} == ${user.id})"
        th:attr="onclick='changeUser(\''+ ${user.id} + '\', \''+ ${user.name} + '\');'">click on me</button>

【问题讨论】:

标签: html thymeleaf


【解决方案1】:

我发现问题出在 Thymeleaf 版本中。

【讨论】:

  • 您可以选择这样做,但请注意 Thymeleaf 版本的“问题”是故意添加到 Thymeleaf 中作为安全功能的。 Thymeleaf 的创建者建议您“对文本字面量变量使用(充分 HTML 转义的)数据属性,” - 请参阅他们的注释 here 以及我在我的 cmets 中链接到的答案问题。
猜你喜欢
  • 1970-01-01
  • 2020-05-16
  • 2021-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-02
  • 2019-08-22
  • 2023-03-31
相关资源
最近更新 更多