使用$('#dividname').文本将新行字符插入div

AMo*_*989 0 html javascript css jquery

我已使用附加<div>到我的页面正文

$('body').append('<div id="itemInfo"><h2>TEST</h2></div>');
Run Code Online (Sandbox Code Playgroud)

这<div>隐藏在我的CSS中.然后我<div>使用函数改变文本,如下所示.

    function appendMessage(messagestring) {
    $('#itemInfo h2').text(messagestring);
    $('#itemInfo').fadeIn();
    $('#itemInfo').fadeOut(3000);   
}
Run Code Online (Sandbox Code Playgroud)

这是使用以下声明.

appendMessage("Something. ");
Run Code Online (Sandbox Code Playgroud)

问题是,我似乎无法获得<br />或/n字符在消息中工作.如何在.text()函数中使用换行符?

小智 5

尝试使用html()函数:

$('#itemInfo h2').html(messagestring);
Run Code Online (Sandbox Code Playgroud)