Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 引导盒-如何动态更改消息内容?_Javascript_Html_Twitter Bootstrap_Bootbox - Fatal编程技术网

Javascript 引导盒-如何动态更改消息内容?

Javascript 引导盒-如何动态更改消息内容?,javascript,html,twitter-bootstrap,bootbox,Javascript,Html,Twitter Bootstrap,Bootbox,我想知道是否有一种方法可以自动更新引导框模式的内容 范例 bootbox.dialog({ message: "Hi there", title: "My title", buttons: { main: { label: "dismiss", className: "btn-primary", } } });

我想知道是否有一种方法可以自动更新引导框模式的内容

范例

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引用来更改引导框消息。下面是它的示例代码

    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");
bootbox.dialog({
留言:“你好”,
标题:“我的标题”,
按钮:{
主要内容:{
标签:“解散”,
类名:“btn主节点”,
}
}
});
//在您要更改消息的任何位置添加此行
$(“#dynamicMsg”).text(“这是动态消息”);

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

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