Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Thymeleaf th:onclick事件-调用确认函数_Spring_Thymeleaf - Fatal编程技术网

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

Spring Thymeleaf th:onclick事件-调用确认函数,spring,thymeleaf,Spring,Thymeleaf,我是新来的。最近我遇到了以下情况。这是我的ThymileAF html页面的一部分: <!-- an delete button link --> <a th:href="@{/employees/delete(employeeId=${tempEmployee.emplId},firstName=${tempEmployee.firstName},lastName=${tempEmployee.lastName})}" class="btn btn-danger bt

我是新来的。最近我遇到了以下情况。这是我的ThymileAF 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>

这段代码按预期工作良好。但是,我想添加员工姓名作为确认的一部分。代码如下:

<!-- 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>

不幸的是,结果是:
是否确实要删除此员工
“++${tempEmployee.firstName}+”

看起来Thymeleaf无法识别${tempEmployee.firstName}。它在th:href标记中没有问题,但不喜欢在th:onclick中使用


如果有人能把我引向正确的方向,我将不胜感激。

不确定到底是什么问题(尽管它可能与
onclick
vs
th:onclick
有关。无论如何,我认为这样的格式会起作用(还有一些额外的好处,比如没有JavaScript注入)



(注意我使用的是
onlick
而不是
th:onclick

而不是上面代码中的这一行
--onclick=“if(!confirm(this.getAttribute('data-confirm-delete'))return false”>

你可以这样写:
onclick=“返回确认(this.getAttribute('data-confirm-delete')”

<!-- 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:data-confirm-delete="|Are you sure you want to delete this employee ${tempEmployee.firstName}?|"
  onclick="if (!confirm(this.getAttribute('data-confirm-delete'))) return false"
>
  Delete
</a>