BootstrapDialog打开后如何防止脚本执行?

How to prevent script execution after BootstrapDialog opens?

我正在使用 BootstrapDialog 来显示一些警报。

    BootstrapDialog.alert({
          type:  BootstrapDialog.TYPE_DANGER,
          title: 'Oops! ',
          message: 'Error, occured',
          buttons: [{
              label: 'Ok'

          }]
      });
    window.location.replace("http://example.com");

我希望当对话框打开时它不会重定向到另一个页面。它应该只在用户单击 "OK" 按钮时重定向,就像我在 javascript.

中使用警报一样

您应该在 buttons 属性中附加 window.location 代码。尝试这样做:

BootstrapDialog.show({
    type:  BootstrapDialog.TYPE_DANGER,
    title: 'Oops! ',
    message: 'Error, occured',
    buttons: [{
        label: 'Ok',
        action: function(dialog) {
            window.location.replace("http://example.com");
        }
    }]
});