【发布时间】:2015-06-14 15:00:49
【问题描述】:
bootbox.alert 应该出现在bootbox.dialog 之前。我已将所有库预加载到 JSFiddle 中。我希望在单击 bootbox.alert 后显示 bootbox.dialog。
【问题讨论】:
标签: javascript jquery html twitter-bootstrap bootbox
bootbox.alert 应该出现在bootbox.dialog 之前。我已将所有库预加载到 JSFiddle 中。我希望在单击 bootbox.alert 后显示 bootbox.dialog。
【问题讨论】:
标签: javascript jquery html twitter-bootstrap bootbox
看看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() {
}
}
}
});
}
});
});
【讨论】: