如何在执行javascript中的进一步语句之前等待bootbox.prompt()结果
How to wait for the bootbox.prompt() result before executing the further statements in javascript?
我有以下代码:
var bootboxresult;
bootbox.prompt('Please enter some data', function(result) {
if (result != null) {
bootboxresult = result;
}});
alert(bootboxresult);
if(bootboxresult === null)
{
return;
}
if(bootboxresult != null)
{
Some Code To Excecute
}
代码显示提示框,但变量"bootboxresult"的内容总是为空或未定义。
我需要进一步的代码应该等待bootbox.prompt()将值存储在"bootboxresult"变量中。
请建议。
我认为你可以在bootbox的回调中编写所有的代码。参见下面的示例。
var popup_content = "<b>Are you sure?</b><br><br>Do you want to delete?";
bootbox.confirm(popup_content, function(result) {
if(result){
// Write all your code here.
}else{
// else part code goes here
}
});
相关文章:
- 单击按钮以等待单击按钮
- React组件等待所需道具进行渲染
- 正在等待呈现图表,直到加载数据为止
- 在等待ajax请求时显示微调器并禁用页面
- Javascript在for循环中等待处理请求
- JavaScript循环并等待函数
- 在等待异步任务时永久循环
- 在通过child.print()打印之前,我如何等待图像加载到我的新窗口中
- 失败:等待Protractor与页面同步时出错:“”;在窗口上找不到角度”;
- 等待300毫秒,然后使用jQuery向下滑动菜单
- 等待循环调用的所有承诺完成
- 等待回调函数执行
- 获取Meteor中自定义Bootbox字段的值
- RxJS等待承诺解决
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- Casperjs等待资源
- draggableCursor没有't更改为等待光标
- 如何使请求等待上一个请求完成
- 更改css链接并等待加载新的css
- 如何在执行javascript中的进一步语句之前等待bootbox.prompt()结果