你好,我有一个使用sweetalert的代码
swal("Good job!", "You clicked the button!", "success")
这段代码将弹出一个消息框,并有一个“好的”按钮,我想要做的是在单击“好的”按钮后刷新页面。
我可以这样做吗?
你好,我有一个使用sweetalert的代码
swal("Good job!", "You clicked the button!", "success")
这段代码将弹出一个消息框,并有一个“好的”按钮,我想要做的是在单击“好的”按钮后刷新页面。
我可以这样做吗?
你可以尝试这个方法,它对我有效。
swal({
title: "Good job",
text: "You clicked the button!",
type: "success"
},
function(){
location.reload();
}
);
Yoshioka的答案对我没有用,但我尝试了以下方法,它完美地解决了我的问题:
swal({title: "Good job", text: "You clicked the button!", type:
"success"}).then(function(){
location.reload();
}
);
使用回调函数来处理异步操作结果。
Swal.fire({
// Swal Setting's
}).then((result) => {
// Reload the Page
location.reload();
});
swal({
title: "Good job",
text: "You clicked the button!",
icon: "success",
buttons: [
'NO',
'YES'
],
}).then(function(isConfirm) {
if (isConfirm) {
location.reload();
} else {
//if no clicked => do something else
}
});
我使用SweetAlert2,这对我有用。
swal("Good job!", "You clicked the button!","success").then( () => {
location.href = 'somepage.html'
})
使用location.reload()的答案会导致您的表单尝试一遍又一遍地重新提交,因此您应该使用location.href。
Swal.fire({
title: 'Great job',
text: "You clicked the button!",
type: 'success',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
if(result){
// Do Stuff here for success
location.reload();
}else{
// something other stuff
}
})
Swal.fire('Deleted !!', data.message, 'success').then(() => {
location.reload();
});
您可以在SweetAlert2上找到参考资料。
Swal.fire(
{
title: "Good job",
text: "You clicked the button!",
type: "success",
showDenyButton: true, // In case you want two scenarios
denyButtonText: 'ABC',
showCancelButton: true, // In case you want two scenarios
cancelButtonText:'XYZ'
}
).then(function (result) {
if (result.isConfirmed) {
//You can add code here if user pressed ok button
} else if (result.isDenied) {
//You can add code here if user pressed deny button
} else if(result.isDismissed) {
//You can add code here if user pressed cancel button
}
)
我用以下代码解决了这个问题:
swal({title: "Updated!", text: "yourText", type: "success"},function() {
location.reload();
}) // swal end
另一种方式:
swal("Updated!","yourText","success",function() {
location.reload();
}) // swal end