如何在javascript中的textContent中添加新行

问题描述 投票:0回答:1
function callBack(data1, predicted_label){
    const resultParagraph = document.getElementById("resultParagraph"); 
    resultParagraph.textContent = `Sentiment: ${predicted_label}`;
    const historyList = document.getElementById("historyList");
    const listItem = document.createElement('li');
    listItem.textContent = `Text: ${data1} Sentiment: ${predicted_label}`;
    historyList.prepend(listItem);  }

在此代码中,我想在

Text: ${data1} Sentiment: ${predicted_label}
之间添加新行。

我尝试添加 ,尝试添加
标签,但似乎没有效果

javascript
1个回答
0
投票

HTML 渲染不考虑换行符 - 您需要使用 innerHTML 而不是 textContent 并在想要换行的位置添加

<br>
标记

© www.soinside.com 2019 - 2024. All rights reserved.