BB对话框显示之前警告
问题描述:
的bootbox.alert
应bootbox.dialog
前露面。我已将所有库预加载到JSFiddle中。一旦bootbox.alert
被点击,我想要bootbox.dialog
显示。
答
检查出来here
Bootbox定义它们的功能here,正如你可以看到他们有一个回调。例如:
bootbox.alert(message, callback)
的callback
让你只运行某些代码的选项,一旦这条线就完成了。这解决了你的问题。
JS
$(document).ready(function() {
$('.begin-game').click(function() {
bootbox.alert("This should show up first", function() {
bootbox.dialog({
message: "Did you pass Go?",
title: "This should go second/last",
buttons: {
// Passed go
success: {
label: "Yes I Passed GO!",
className: "btn-success",
callback: function() {
}
},
// Did not pass go
danger: {
label: "I did not :(",
className: "btn-danger",
callback: function() {
}
},
}
});
});
});
});
答
到bootbox.alert
的第二个参数是一个function
警报被驳回后,将调用。在该功能中启动对话框。
$(document).ready(function() {
$('.begin-game').click(function() {
bootbox.alert("This should show up first", showDialog);
function showDialog() {
bootbox.dialog({
message: "Did you pass Go?",
title: "This should go second/last",
buttons: {
// Passed go
success: {
label: "Yes I Passed GO!",
className: "btn-success",
callback: function() {
}
},
// Did not pass go
danger: {
label: "I did not :(",
className: "btn-danger",
callback: function() {
}
}
}
});
}
});
});