Kle*_*ota 19 javascript spring onclick thymeleaf spring-boot
在我目前的spring-boot项目中,我有一个带有这个html代码的视图:
<button type="button" class="btn btn-primary" onclick="upload()" th:utext="#{modal.save}"></button>
Run Code Online (Sandbox Code Playgroud)
在onclick
属性中,对函数的调用upload()
应该有一个参数,该值存储在thymeleaf变量中${gallery}
.
任何人都可以告诉我如何在上面的命令中使用表达式?
我已经尝试过了:
th:onclick="upload(${gallery)"
th:attr="onclick=upload(${gallery)"
这些都没有奏效.
Kle*_*ota 27
我用这种方法解决了这个问题:
th:onclick="|upload('${command['class'].simpleName}', '${gallery}')|"
Run Code Online (Sandbox Code Playgroud)
小智 11
thymeleaf 3.0.10 th:onclick thymeleaf变量不起作用
这应该工作:
th:attr="onclick=|upload('${gallery}')|"
Run Code Online (Sandbox Code Playgroud)
snw*_*snw 10
这应该工作:
<button th:onclick="'javascript:upload(' + ${gallery} + ')'"></button>
Run Code Online (Sandbox Code Playgroud)
在 Thymeleaf 3.0.10 版本中
使用 [[]] 更容易,thymeleaf 去注入模板中的值
如果值是字符串,则不需要引号
<button th:data-id="${quartzInfo.id}"
th:onclick="del(this,[[${quartzInfo.id}]]" type="button">
</button>
Run Code Online (Sandbox Code Playgroud)
旧的回复在新版本3.0.10中不起作用。现在你需要:
<button th:data-id="${quartzInfo.id}"
onclick="del(this,this.getAttribute('data-id'))" type="button">
</button>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
31774 次 |
最近记录: |