javascript - 在 onclick 属性中使用 thymeleaf 变量

标签 javascript spring onclick spring-boot thymeleaf

在我当前的 spring-boot 项目中,我对这段 html 代码有一个看法:

<button type="button" class="btn btn-primary" onclick="upload()" th:utext="#{modal.save}"></button>

onclick属性中,对upload()函数的调用应该有一个参数,该参数存储在thymeleaf变量${gallery}中.

谁能告诉我上面命令中的表达式怎么用?

我已经尝试过了:

  • th:onclick="upload(${gallery)"

  • th:attr="onclick=upload(${gallery)"

这些都不起作用。

最佳答案

thymeleaf 3.0.10 th:onclick thymeleaf 变量不起作用

这应该可行:

th:attr="onclick=|upload('${gallery}')|" 

关于javascript - 在 onclick 属性中使用 thymeleaf 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32650536/

相关文章:

javascript - Promise.all 在 foreach 循环之后

java - 未找到 getView() 和 getActivity()

java - 如何让方法暂停并等待 Android 的输入?

javascript - Onclick 函数在外部 javascript 文件中不起作用

php - 如何在 PHP 中实现事件驱动代码?

javascript - 使用 grunt 安装启动项目时出错

java - 如何用spring处理CompletionStage?

java - ExceptionHandler 调用但不影响 http 响应

spring - 嵌套异常是 redis.clients.jedis.exceptions.JedisConnectionException : Could not get a resource from the pool

javascript - Angular 用指向页面片段的链接替换 ​​html 内容