只需添加一個回調函數作爲SwaI位的()
swal({
title: "Auto close alert!",
text: "I will close in 2 seconds.",
timer: 2000
},
function(){
// SweetAlert confirmed, do something
$('.classMyTextField').focus();
}
);
要做些什麼的時候SweetAlert是證實或取消第二個參數:
swal({
title: "Auto close alert!",
text: "I will close in 2 seconds.",
timer: 2000
},
function(isConfirmed){
if(isConfirmed){
swal("Confirmed!", "You confirmed the alert.", "success");
$('.classMyTextField').focus();
}
else{
swal("Cancelled!", "You cancelled the alert.", "warning");
}
}
);
UPDATE :
要僅顯示通知沒有確認或取消按鈕:
swal({
title: "Auto close alert!",
text: "I will close in 2 seconds.",
timer: 2000,
showConfirmButton: false,
showCancelButton: false
},
function(){
// alert closed
$('.classMyTextField').focus();
}
);
我試過了,但仍不能專注......你有另一種解決方案? –