【问题标题】:bootbox 4.4 how to alert with different button labelbootbox 4.4 如何使用不同的按钮标签进行警报
【发布时间】:2016-05-02 19:42:49
【问题描述】:

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

但是在 4.4 版这个方法似乎不起作用,我怎样才能在警报消息上使用自定义按钮标签

【问题讨论】:

    标签: javascript jquery angularjs popup bootbox


    【解决方案1】:

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

    【讨论】:

    • 我希望他们在文档中有这个
    • 嗨,我还有一个问题要问你。也许您可以帮助我,我正在尝试在 bootbox.confirm 中设置确认按钮,然后再取消按钮。我必须在所有引导箱上都这样做,所以也许我可以配置一次而不是每个单独的元素?
    • 目前没有办法交换按钮的顺序。如果您确实需要按钮的特定顺序,您可以修改源代码。
    • 你知道它在哪里吗?
    • 取决于你所说的“它”是什么意思。
    【解决方案2】:

    你可以试试这样的:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      相关资源
      最近更新 更多