在HTML内容中输出javascript变量

时间:2017-03-15 09:27:36

标签: javascript php twitter-bootstrap

我正在使用https://nakupanda.github.io/bootstrap3-dialog/并遇到此功能:

function hello(msg) {
        BootstrapDialog.show({
            title: 'Button Hotkey',
            message: $('<textarea id="try" class="form-control">//how do I output msg variable here?</textarea>')
        });
    }  

现在正确加载了msg变量(使用alert(msg)进行了测试),但我不知道如何在<textarea>msg?</textarea>标记中包含要输出的值

1 个答案:

答案 0 :(得分:0)

如果我正确理解了这个问题,那么&#39; msg&#39;通过将变量添加到HTML模板字符串,可以在Textarea中打印变量,如下所示,

BootstrapDialog.show({
        title: 'Button Hotkey',
        message: $('<textarea id="try" class="form-control">'+ msg +'</textarea>')
    });