bootbox 4.4 如何用不同的按钮标签提醒

bootbox 4.4 how to alert with different button label

我在 bootbox v3 文档中看到您可以使用以下方法更改标签 bootbox.alert(str message, str label, fn callback) 自定义按钮文本,关闭时调用的回调,

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

您可以尝试这样的操作:

bootbox.alert({ 
   size: 'small',
   message: "Your message here…", 
   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

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

$(function() {
  bootbox.alert({
    message: 'I have a custom OK button',
    buttons: {
      ok: {
        label: 'Right on!'
      }
    }
  })
})
<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>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>

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