【问题标题】:Thymeleaf onclick send string as parameter value to javascript functionThymeleaf onclick 将字符串作为参数值发送到 javascript 函数
【发布时间】:2019-11-17 23:56:03
【问题描述】:

我想在从 Thymeleaf 到 javascript 函数的 onClick 上传递多个参数。

<label th:onclick="getUserId(userId,email);" for="radio-11" data-toggle="tooltip" data-placement="bottom" data-trigger="hover"  class="pm-tab1-pad">

我的 Javascript 函数是:-

<script>
   function getUserId(userID,userEmail){
      console.log(userID,userEmail);
    }
</script>

怎么做?

【问题讨论】:

  • 您是否检查过您的标签在没有传递任何参数的情况下被点击?试试这样&lt;ELEMENT onclick="handler"&gt;
  • 是的,我已经检查过了。

标签: thymeleaf


【解决方案1】:

可以通过以下方式完成:-

<label th:onclick="getUserId([[${userId}]],[[${email}]] );" for="radio-11" data-toggle="tooltip" data-placement="bottom" data-trigger="hover"  class="pm-tab1-pad">

这里,userId 是 Integer 类型 end email 是 String 类型。

更新:-

这也有效:-

<label th:data-parameter1="${userId}" th:data-parameter2="${email}"  th:onclick="getUserId(this.getAttribute('data-parameter1'),this.getAttribute('data-parameter2'));" for="radio-11" data-toggle="tooltip" data-placement="bottom" data-trigger="hover"  class="pm-tab1-pad">

【讨论】:

猜你喜欢
  • 2023-03-20
  • 2021-08-08
  • 2011-12-27
  • 2014-07-09
  • 2011-04-30
  • 1970-01-01
  • 2016-12-04
  • 1970-01-01
  • 2021-08-10
相关资源
最近更新 更多