在onclick属性中使用thymeleaf变量 [英] Using thymeleaf variable in onclick attribute
本文介绍了在onclick属性中使用thymeleaf变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我当前的spring-boot项目中,我使用此html代码查看了一个视图:
In my current spring-boot project, I have one view with this html code:
<button type="button" class="btn btn-primary" onclick="upload()" th:utext="#{modal.save}"></button>
在onclick
属性中的
中,对函数upload()
的调用应具有一个参数,该值存储在百里香叶变量${gallery}
中.
in the onclick
attribute, the call for the function upload()
should have one parameter, which value is stored in the thymeleaf variable ${gallery}
.
任何人都可以告诉我如何在上述命令中使用该表达式吗?
Anyone can tell mehow to use the expression in the above command?
我已经尝试过:
-
th:onclick="upload(${gallery)"
th:attr="onclick=upload(${gallery)"
这些都不起作用.
推荐答案
我用这种方法解决了这个问题:
I solve this issue with this approach:
th:onclick="|upload('${command['class'].simpleName}', '${gallery}')|"
这篇关于在onclick属性中使用thymeleaf变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文