在javascript中执行进一步语句之前,如何等待bootbox.prompt()结果?
我有以下代码:在javascript中执行进一步语句之前,如何等待bootbox.prompt()结果?,javascript,bootstrap-modal,bootbox,Javascript,Bootstrap Modal,Bootbox,我有以下代码: 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 Excecu
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”变量的内容始终为null或未定义
我需要进一步的代码等待bootbox.prompt()将值存储在“bootboxresult”变量中
请告知。我认为您可以将所有代码写在引导箱的回调中。见下面的例子
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
}
});
var popup\u content=“确定吗?
要删除吗?”;
引导框。确认(弹出内容、功能(结果){
如果(结果){
//在这里编写所有代码。
}否则{
//否则部分代码在这里
}
});
Thank@CBroe的可能重复,它帮助并清除了我的同步和异步调用概念。