简体   繁体   English

如何使用 thymeleaf 属性 th:href 调用 java 脚本函数?

[英]How to call java script function using thymeleaf attribute th:href?

I have written like this in my HTML page:我在我的 HTML 页面中是这样写的:

 <a th:href="@{javascript:deleteContact('deletemainmenu?id=${var[0]}')}">
 </a>

And my script is:我的脚本是:

 function deleteContact(url)
 {
     var isOK = confirm("Are you sure to delete?");
     if(isOK)
     {
       go(url);
      }
 }

It's showing an error:它显示一个错误:

Could not parse as expression: " @{javascript:deleteContact('deletemainmenu?id=${var[0]}')} "无法解析为表达式:“ @{javascript:deleteContact('deletemainmenu?id=${var[0]}')}

How can i call javascript using th:href ?我如何使用th:href调用 javascript?

<html>
<head>

<script>
    function deleteContact(url)
     {
         var isOK = confirm("Are you sure to delete?");
         if(isOK)
         {
           go(url);
          }
     }
</script>
</head>
<body>
<a href="javascript:deleteContact('param value')">Test </a>
</body>
</html>
<script type="text/javascript">
    function getkey(a) 
    {
        var pms =  document.getElementById("textkey").value;
        a.href = '/allTransaction' + pms;
    }
</script>

<input  id="textkey" type="text" name="">
<a href="" onclick="getkey(this)">gogogo</a>

I think the solution you wanted is something like that我认为你想要的解决方案是这样的

function myFunction(name,t) {
...
}

<a class="nav-link" th:href="'javascript:myFunction(&quot'+${category}+'&quot,1);'">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM