bootbox 4.4如何使用不同的按钮标签进行警报

时间:2016-05-02 19:42:50

标签: javascript jquery angularjs popup bootbox

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

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

2 个答案:

答案 0 :(得分:5)

您可以使用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覆盖为按钮。

答案 1 :(得分:1)

您可以尝试这样的事情:

bootbox.alert({ 
   size: 'small',
   message: "Your message here…", 
   callback: function(){ /* your callback code */ }
}).init(function(){ 
    $('.btn.btn-primary').text('Custom Text')
});
  

来自文档: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