Using thymeleaf variable in onclick attribute

前端 未结 6 1070
不知归路
不知归路 2021-02-01 18:15

In my current spring-boot project, I have one view with this html code:

相关标签:
6条回答
  • 2021-02-01 18:25

    thymeleaf 3.0.10 th:onclick thymeleaf variable not working

    This should work:

    th:attr="onclick=|upload('${gallery}')|" 
    
    0 讨论(0)
  • 2021-02-01 18:30

    yes it's to late, but i hope this will help people who need it

    try this

    th:onclick="'upload('+${gallery}+')'"
    
    0 讨论(0)
  • 2021-02-01 18:33

    This should work:

    <button th:onclick="'javascript:upload(' + ${gallery} + ')'"></button>
    
    0 讨论(0)
  • 2021-02-01 18:38

    In 3.0.10 version of Thymeleaf

    use [[ ]] it's more easier , thymeleaf goes to inject the value in template

    if the value is string no quote need

    <button th:data-id="${quartzInfo.id}" 
        th:onclick="del(this,[[${quartzInfo.id}]]" type="button">
    </button>
    
    0 讨论(0)
  • 2021-02-01 18:46

    The older replies does not work in the new version of 3.0.10. Now you need:

    <button th:data-id="${quartzInfo.id}" 
        onclick="del(this,this.getAttribute('data-id'))" type="button">
    </button>
    
    0 讨论(0)
  • 2021-02-01 18:47

    I solve this issue with this approach:

    th:onclick="|upload('${command['class'].simpleName}', '${gallery}')|"
    
    0 讨论(0)
提交回复
热议问题