Thymeleaf:传递javascript参数

编程入门 行业动态 更新时间:2024-10-25 04:13:47
本文介绍了Thymeleaf:传递javascript参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个基本的 SpringBoot 应用程序.使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件.我想将 POJO 的属性传递给 javascript 函数:

I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I want to pass an attribute of a POJO to a javascript function:

<tr th:each="company: ${companies}" > <td class="col_actions"> <a th:href="@{/company/edit/{id}(id=${company.id})}" style="color:#808080; margin-right: 10px;"> <i class="fa fa-pencil-square-o" aria-hidden="true"></i> </a> <a href="#" style="color:#808080; text-align: center;" onclick="javascript:confirmDelete ({id}(id=${company.id}));"> <i class="fa fa-times" aria-hidden="true" ></i> </a> </td> </tr>

但是我得到一个错误:Uncaught SyntaxError: missing ) after argument list

推荐答案

问题出在anchor上,如果confirmDelete()函数需要字符串id,请试试这个方法

The problem came from anchor, so please try this one if the confirmDelete() function require a string id

th:onclick="'javascript:confirmDelete(\'' + ${company.id} + '\');'"

如果它需要一个号码 id

And if it need a number id

th:onclick="'javascript:confirmDelete(' + ${company.id} + ');'"

更多推荐

Thymeleaf:传递javascript参数

本文发布于:2023-10-12 01:28:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   Thymeleaf   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!