Javascript Sweetalert延迟打开弹出窗口
我试图延迟SweetAlert弹出窗口,使其在触发后几秒钟内不显示 e、 g.用户在网页上执行操作以触发SweetAlert,但它不是立即显示,而是等待2秒钟,然后显示。-我一直在研究各种方法来实现这一点,但运气不好……我想可能需要Javascript Sweetalert延迟打开弹出窗口,javascript,alert,sweetalert,sweetalert2,Javascript,Alert,Sweetalert,Sweetalert2,我试图延迟SweetAlert弹出窗口,使其在触发后几秒钟内不显示 e、 g.用户在网页上执行操作以触发SweetAlert,但它不是立即显示,而是等待2秒钟,然后显示。-我一直在研究各种方法来实现这一点,但运气不好……我想可能需要setTimeout 以下是我的SweetAlert功能,该功能目前正在运行: if( response == 10 ){ swal({ type: 'success', title: 'YOUR BALANCED BOX IS FUL
setTimeout
以下是我的SweetAlert功能,该功能目前正在运行:
if( response == 10 ){
swal({
type: 'success',
title: 'YOUR BALANCED BOX IS FULL',
text: 'Youve added the recommended amount of items for your plan!',
allowOutsideClick: false,
showCancelButton: true,
cancelButtonText: "Modify Selection",
cancelButtonColor: '#d33',
showConfirmButton: true,
confirmButtonColor: '#61ce70',
confirmButtonText: "Proceed To Cart",
}).then((result) => {
if (result.value) {
window.location = "/basket/";
}
})
}
感谢您的帮助 是的,您确实可以使用setTimeout轻松实现这一点,我设置了一个简单的代码片段,您可以尝试一下
//单击按钮时。
$(“#按钮”)。单击(()=>{
//立即将其文本更改为加载。。
$(“#按钮”).text(“加载!”);
//等待2毫秒,然后将文本更改为“完成”!
设置超时(()=>{
$(“#按钮”).text(“完成!”;
}, 2000);
})
事件
特定的SWEETALERT 2回答:
以上Leo的代码逻辑回答是正确的。我正在与SweetAlert 2共享最终版本,其中添加了setTimeout
作为延迟弹出窗口打开的功能
setTimeout
函数环绕整个SweetAlert 2函数,计时器设置在函数末尾的底部(在本例中为3000)
希望这能帮助任何想做同样事情的人
setTimeout(function(){swal({
type: 'success',
title: 'YOUR BALANCED BOX IS FULL',
text: 'Youve added the recommended amount of items for your plan!',
allowOutsideClick: false,
showCancelButton: true,
cancelButtonText: "Modify Selection",
cancelButtonColor: '#d33',
showConfirmButton: true,
confirmButtonColor: '#61ce70',
confirmButtonText: "Proceed To Cart",
}).then((result) => {
if (result.value) {
window.location = "/basket/";
}
})},3000);
setTimeout可以用吗?谢谢Leo!帮助我找到答案-已将您的标记为正确,并在下面添加了具体的解决方案。