我有一个基本的SpringBoot应用程序。使用Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎以及作为可执行JAR文件的软件包。我想将POJO的属性传递给javascript函数:
<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
Uncaught SyntaxError: missing ) after argument list
问题来自锚点,因此如果confirmDelete()函数需要字符串ID ,请尝试使用此方法
confirmDelete()
th:onclick="'javascript:confirmDelete(\'' + ${company.id} + '\');'"
如果需要数字编号
th:onclick="'javascript:confirmDelete(' + ${company.id} + ');'"