关于javascript:bootbox 4.4如何使用不同的按钮标签进行提醒

bootbox 4.4 how to alert with different button label

我看到bootbox v3文档中可以使用以下方法更改标签
bootbox.alert(str消息,str标签,fn回调)自定义按钮文本,解雇后调用回调,

但是在4.4版上,此方法似乎不起作用,我如何在警报消息上使用自定义按钮标签


您可以使用buttons选项覆盖任何对话框的文本(这要求您使用options对象来设置对话框)。例如,这是一个自定义警报:

1
2
3
4
5
6
7
8
9
10
$(function() {
  bootbox.alert({
    message: 'I have a custom OK button',
    buttons: {
      ok: {
        label: 'Right on!'
      }
    }
  })
})
1
2
3
4
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js">

为确认和提示,您可以覆盖confirmcancel作为按钮。


您可以尝试以下操作:

1
2
3
4
5
6
7
bootbox.alert({
   size: 'small',
   message:"Your message herea€|",
   callback: function(){ /* your callback code */ }
}).init(function(){
    $('.btn.btn-primary').text('Custom Text')
});

From the docs: bootbox.init(function): Allows the user to supply a function to be called when dialog gets initialized.
http://bootboxjs.com/documentation.html#bb-public-methods