我正在laravel中编写一个项目,在我目前的工作流程中,我希望用户能够单击按钮发布或从当前列表中删除事件 .
我正在使用SA2在路由发生前停止提交路由,如果用户点击OK,则一切按计划进行,当用户点击取消时,我想重定向回页面 .
我遇到的问题是,当用户点击取消时,无论如何都会重定向到页面...
function warnRemove(linkURL) {
swal({
title: 'Are you sure?',
type: 'warning',
showCancelButton: true,
confirmButtonColor: 'D6B55',
confirmButtonText: 'Yes, remove it!'
}).then(function () {
window.location = linkURL;
});
}
function warnPublish(linkURL) {
swal({
title: 'Are you sure?',
type: 'warning',
text: 'This event will go live on the screen after next refresh.',
showCancelButton: true,
confirmButtonColor: 'D6B55',
confirmButtonText: 'Yes, publish it!'
}).then(function () {
window.location = linkURL;
});
}
$('.remove').click(function(e) {
e.preventDefault(); // Prevent the href from redirecting directly
let linkURL = $(this).attr("href");
warnRemove(linkURL);
});
$('.publish').click(function(e) {
e.preventDefault(); // Prevent the href from redirecting directly
let linkURL = $(this).attr("href");
warnPublish(linkURL);
});
1 回答
您将需要使用带有isConfirm布尔值的回调:
来自文档: