如何在执行 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"变量的内容始终为null或undefined。
我需要进一步的代码等待 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
}
});
我有以下代码:
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或undefined。
我需要进一步的代码等待 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
}
});