小编Met*_*ids的帖子

Thymeleaf th:onclick 事件 - 调用确认函数

我是百里香新手。最近我无意中遇到了以下情况。这是我的 Thymeleaf html 页面的一部分:

<!-- an delete button link -->
<a th:href="@{/employees/delete(employeeId=${tempEmployee.emplId},firstName=${tempEmployee.firstName},lastName=${tempEmployee.lastName})}"
    class="btn btn-danger btn-sm py-1 "
    th:onclick="if(!(confirm('Are you sure you want to delete this employee ?') )) return false" >
    Delete
</a>
Run Code Online (Sandbox Code Playgroud)

这段代码按预期工作得很好。不过,我想添加员工姓名作为确认的一部分。这是代码:

<!-- an delete button link -->
<a th:href="@{/employees/delete(employeeId=${tempEmployee.emplId},firstName=${tempEmployee.firstName},lastName=${tempEmployee.lastName})}"
    class="btn btn-danger btn-sm py-1 "
    th:onclick="if(!(confirm('Are you sure you want to delete this employee ' + '\'+${tempEmployee.firstName}+\'' +'?' ) )) return false" >
    Delete
</a>
Run Code Online (Sandbox Code Playgroud)

不幸的是结果是: Are you sure you want to delete this employee '+${tempEmployee.firstName}+'

Thymeleaf …

spring thymeleaf

6
推荐指数
1
解决办法
4356
查看次数

标签 统计

spring ×1

thymeleaf ×1