javascript - 如何让代码执行等到在 Sweetalert 提示符中输入值?
问题描述
我想代码执行等到在甜蜜警报提示中输入一个值。基本上,我想要一个与基本 js 提示相同的甜蜜警报提示的阻止行为。
let value= Swal.fire({
title: "An input!",
text: "Write something interesting:",
input: 'text',
showCancelButton: true
})
这是将值存储在“值”中的甜蜜警报提示代码。现在,操作是异步的。我希望进一步的代码执行等到我没有得到值。
如果除了 sweet alert 之外还有其他库可以执行预期的行为,我对此很感兴趣。我想要的只是一个带有阻塞行为的风格化提示。
解决方案
我相信甜蜜的警报可以处理承诺。所以当你执行你的代码时,你可以做
value.then( (foo) => {
// your code goes here after the input is received
})
或者,如果您不想将其存储在变量中而只运行原始的甜蜜警报代码:
Swal.fire({
title: "An input!",
text: "Write something interesting:",
input: 'text',
showCancelButton: true
})
.then((foo) => {
// your code goes here after the input is received
});
在这种情况下, foo 将是用户提供的输入
推荐阅读
- local-storage - X3DOM ImageTexture url找不到本地文件
- laravel - 数据透视表上的一对多关系
- java - android studio 中是否有 Sun 的包的替代品
- sql - 选择每个部门和工资高于 10000 的员工人数
- testing - 什么是 Benjamini-Yekutieli 测试
- python - Discord.py ctx.guild.edit 有效,但 self.bot.guild.edit 无效?
- google-analytics - 如何从 Google Analytics(分析)报告中删除 URL 参数
- arduino - 如何将 4 欧姆 3 瓦扬声器连接到 arduino mega?
- sql - 无法正确创建触发器
- tableau-api - Tableau 不支持 CHARINDEX 函数