14

在 Bootbox 3.2.0 中,我能够使用以下传递的字符串进行确认:

bootbox.confirm(
    confirm_string, 
    cancel_string, 
    yes_string,
    function(r) {           
        if (r) {
            //do something
        }
    }
);

我正在升级到 4.1.0,但上述函数调用出现错误。

根据 Bootbox 4.1.0 的文档(http://bootboxjs.com/documentation.html),有两种方式调用confirm:

bootbox.confirm(str message, fn callback)    
bootbox.confirm(object options)

我用消息字符串和回调函数测试了第一种方式,它可以工作。对于第二种方式,我能够传递一个对象,如下所示:

{
  message: message_string
  callback: function(r) {
    //do something
  }
}

如何以第二种方式传递 OK、Cancel 按钮的字符串?

谢谢并恭祝安康。

4

3 回答 3

17

作为替代方案,这也可以直接使用 来完成bootbox.confirm,如下所示:

bootbox.confirm({
    buttons: {
        confirm: {
            label: 'Localized confirm text',
            className: 'confirm-button-class'
        },
        cancel: {
            label: 'Localized cancel text',
            className: 'cancel-button-class'
        }
    },
    message: 'Your message',
    callback: function(result) {
        console.log(result);
    },
    title: "You can also add a title",
});
于 2014-04-22T12:24:02.043 回答
9

或使用本地化 - 选项,按默认更改所有按钮:

    bootbox.setDefaults({
          /**
           * @optional String
           * @default: en
           * which locale settings to use to translate the three
           * standard button labels: OK, CONFIRM, CANCEL
           */
          locale: "de"
    });

看过:http ://bootboxjs.com/documentation.html ,“辅助方法”

于 2014-07-20T16:48:05.870 回答
7

您可以使用“自定义对话框”( bootbox.dialog) 来更改这些字符串。

bootbox.dialog({
  message: "Custom message",
  title: "Custom title",
  buttons: {
    danger: {
      label: "Custom Cancel",
      className: "btn-danger",
      callback: function() {
        //do something
      }
    },
    main: {
      label: "Custom OK",
      className: "btn-primary",
      callback: function() {
        //do something else
      }
    }
  }
});
于 2013-11-06T10:19:14.603 回答