我在 Thymeleaf 模板中有这个函数来创建 URL
/company/delete/id
有了这个功能
function confirmDelete (id) {
var r = confirm("Are you sure to delete the item #" + id + " ?");
if (r == true) {
var link = /*[[@{/company/delete/}]]*/ + id;
window.location.href = link;
}
}
但是 id 被忽略,生成的 URL 是没有 id 的 /company/delete/
最佳答案
当您像这样注释掉 Thymeleaf/javascript 时,Thymeleaf 正在尝试创建 JavaScript natural templates work 。它会删除评论结束后的所有内容,因为它认为您正在尝试使模板工作,既使用 Thymeleaf 进行处理,又只是在浏览器中查看它而不进行处理。
您应该只移动要附加 id 的位置。
function confirmDelete (id) {
var r = confirm("Are you sure to delete the item #" + id + " ?");
if (r == true) {
var link = /*[[@{/company/delete/}]]*/ "";
window.location.href = link + id;
}
}
关于javascript - thymeleaf : create URL with parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44256118/