我附加了一个 <div>
使用
$('body').append('<div id="itemInfo"><h2>TEST</h2></div>');
这<div>
隐藏在我的CSS中。然后,我将更改 <div>
中的文本使用如下函数。
function appendMessage(messagestring) {
$('#itemInfo h2').text(messagestring);
$('#itemInfo').fadeIn();
$('#itemInfo').fadeOut(3000);
}
这是使用以下声明的。
appendMessage("Something. ");
问题是,我似乎无法获得 <br />
或 /n
在消息中工作的字符。如何在 .text()
中使用换行符功能?
最佳答案
尝试使用 html() 函数:
$('#itemInfo h2').html(messagestring);
关于javascript - 使用 $ ('#dividname' ).text 将换行符插入 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32213246/