【发布时间】:2020-02-23 05:02:05
【问题描述】:
我有一个使用 .EJS 模板的 Node JS/Express 应用程序,我正在使用以下代码在编辑或删除记录之前弹出标准的“你确定吗”消息。这两个都工作正常:
<a id="edit-form" href="/blog/<%-blog._id%>/edit" onclick="return confirm('Are you sure you wish to edit this blog post?');">
<div class="new-show-icons"><i class="far fa-edit"></i></div>
</a>
<form id="btn-form" action="/blog/<%- blog._id %>?_method=DELETE" method="POST" onclick="return confirm('Are you sure you wish to delete this blog post?');">
<div class="new-show-icons"><i class="far fa-trash-alt"></i></div>
</form>
这是迄今为止我为弹出窗口提供的 JS 代码,但我不确定 1)如何替换这些弹出窗口来代替标准的 html 确认消息,以及 2)如何指定应该采取的操作用户确认或取消时采取(编辑时将其带到编辑页面,删除时直接删除记录)。任何帮助表示赞赏。谢谢
function areYouSureEdit() {
swal({
title: "Are you sure you wish to edit this record?",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes!',
closeOnConfirm: false,
},
function(){
});
};
function areYouSureDelete() {
swal({
title: "Are you sure you wish to delete this record?",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false,
},
function(){
swal("Deleted!", "Your imaginary file has been deleted!", "success");
});
};
但是,我想确保“甜蜜警报”确认消息,我正在努力解决这个问题。
【问题讨论】:
标签: node.js express ejs sweetalert sweetalert2