亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SweetAlert確認后關閉的問題

SweetAlert確認后關閉的問題

尚方寶劍之說 2018-08-08 07:39:41
最近用上了swal,項目需要,colseOnConfirm:true,因為“點擊之后提示框不能loading住頁面,不能防止用戶再次點擊”,所以設為true點擊之后關閉,設為true問題又來了,如果執行太快里面的swal就不會彈出提示了,需要setTimeOut等待幾秒鐘才能彈出提示,真是蛋疼,你們有什么好的方法啊
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

因為動畫有延遲, 可以用promise,進行二次封裝。

window.mconfirm = function (options) {
var prom = new Promise(function (resolve, reject) {
var swalOptions = {
title: "",
text: "",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "確認",
cancelButtonText: "取消",
closeOnConfirm: true,
closeOnCancel: true
};

if (typeof(options) == 'object') {
swalOptions = $.extend(swalOptions, options);
} else {
swalOptions = $.extend(swalOptions, {text: options});
}

swal(swalOptions, function (isConfirm) {
setTimeout(function () {
if (isConfirm) {
resolve(isConfirm);
} else {
reject(isConfirm);
}
}, 100);
});
});
return prom;
};

window.mprompt = function (options) {
var prom = new Promise(function (resolve, reject) {
var swalOptions = {
title: "",
text: "Write something interesting:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: "確認",
cancelButtonText: "取消",
inputPlaceholder: "Write something"
};

if (typeof(options) == 'object') {
swalOptions = $.extend(swalOptions, options);
} else {
swalOptions = $.extend(swalOptions, {text: options});
}

swal(swalOptions, function (inputValue) {
if (inputValue === false || inputValue === "") return false;
swal.close();
setTimeout(function () {
resolve(inputValue);
}, 100);
});
});

return prom;
};


查看完整回答
反對 回復 2018-08-20
  • 1 回答
  • 0 關注
  • 1978 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號