使用Javascript的换行符

使用Javascript的换行符,javascript,html,line-breaks,Javascript,Html,Line Breaks,所以,我有一堆数组数据,我想用HTML编写,但对于其中一些数据,我需要插入换行符,而不是将它们仅仅显示为段落。下面是一个例子 let welcome= document.createElement("div") welcome.setAttribute('id', 'welcome') welcome.className = 'w3-container w3-center w3-animate-opacity'

所以,我有一堆数组数据,我想用HTML编写,但对于其中一些数据,我需要插入换行符,而不是将它们仅仅显示为段落。下面是一个例子

        let welcome= document.createElement("div")
        welcome.setAttribute('id', 'welcome')
        welcome.className = 'w3-container w3-center w3-animate-opacity'
        let welcomeTextNode = document.createTextNode(`Hi, using the side bar, you can find the information regarding your subject.`)        
        welcome.appendChild(welcomeTextNode)
        document.body.appendChild(welcome)
页面上的输出应该是这样的

Hi,
using the side bar, you can find the information regarding your subject.
Hi, [object HTMLBRELEMENT] using the side bar, you can find the information regarding your subject.
我尝试添加“\n”,但即使在html代码中添加了换行符,它仍然在页面上显示为一行。我尝试在字符串中插入“
”,希望它将其视为标记,但它将其视为字符串的一部分,并显示如下

Hi, <br> using the side bar, you can find the information regarding your subject.
但它是这样表现的

Hi,
using the side bar, you can find the information regarding your subject.
Hi, [object HTMLBRELEMENT] using the side bar, you can find the information regarding your subject.
我别无选择

我确信可以使用ignjavascript修改页面上显示的文本,但我不知道怎么做


寻找善意的答案。

您只需使用
innerHTML
即可

let welcome=document.createElement(“div”);
welcome.setAttribute('id','welcome');
welcome.className='w3容器w3中心w3动画不透明度'
welcome.innerHTML=“您好,
使用侧栏,您可以找到 关于你的主题的信息”; document.body.appendChild(欢迎);
使用
innerHTML
,您可以将类似

的html元素放入字符串中

输出:

hi, 
using the side bar, you can find the information regarding your subject"

那么
welcome.innerHTML='您好,
使用侧栏,您可以找到有关主题的信息。