gpt4 book ai didi

javascript - 使用 $ ('#dividname' ).text 将换行符插入 div

转载 作者:太空宇宙 更新时间:2023-11-03 20:36:43 24 4
gpt4 key购买 nike

我附加了一个 <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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com