Bootbox - 如何动态更改消息内容?

Bootbox - how to dynamically change message content?

我想知道是否有一种动态更新引导框模态内容的方法。

示例

bootbox.dialog({
        message: "Hi there",
        title: "My title",
        buttons: {
            main: {
                label: "dismiss",
                className: "btn-primary",
            }
        }
    });


    newMessage = "this is a new message"

有没有办法用新字符串 newMessage 替换 "Hi there"?

感谢任何帮助或建议

简单!创建通用函数:

function bootBoxModal(title, message, type) {
    bootbox.dialog({
        message: message,
        title: title,
        alertType: type,
        buttons: {
            main: {
                label: 'Fechar', className: 'btn-default'}
        }
    });
}

现在调用函数:

bootBoxModal("Title message", 
             "Content your message", 
             "type [alert,danger,warning,success]");

是的,您可以通过将 id 引用添加到 msg 来更改 bootbox msg。下面是它的示例代码。

    bootbox.dialog({
       message: "<span id='dynamicMsg'>Hi there</span>",
       title: "My title",
       buttons: {
        main: {
            label: "dismiss",
            className: "btn-primary",
        }
      }
    });

    //Add this line wherever you want to change msg
    $("#dynamicMsg").text("This is dynamic msg");

另一种方案就是直接替换内容,本例使用jQuery。

#jQuery
$('.modal-title').html('New Title');
$('.modal-body').html('New Message');