BB对话框显示之前警告

问题描述:

JSFiddle Link:BB对话框显示之前警告

bootbox.alertbootbox.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() { 

         } 
        } 
       } 
      });   
     } 
    }); 
});