美文网首页
将Thymeleaf模板变量作参数传递到onclick事件

将Thymeleaf模板变量作参数传递到onclick事件

作者: 蓦然回首_你已不在 | 来源:发表于2018-03-23 20:29 被阅读0次

    情景:

    假设要调用如下js函数, 且要将thymeleaf模板中的user对象的name和password做参数传入.

    <script>
      function test(name, password){
             alert("name: " + name + " password:" + password);
      }
    </script>
    
    • 方法一: 通过|...|, 操作符(ps: 个人认为最简单)
     <button th:onclick="|test('${user.name}','${user.password}' )|">测试</button>
    

    相关文章

      网友评论

          本文标题:将Thymeleaf模板变量作参数传递到onclick事件

          本文链接:https://www.haomeiwen.com/subject/xcpxcftx.html