我尝试添加到本地存储变量新行但我不知道如何做到这一点。我有这个功能:
function showHistory()
{
if (!localStorage.history)
{
localStorage.history = "";
}
localStorage.history = localStorage.history +"something"+"XX";
document.getElementById('history').textContent = localStorage.history;
}
但如果我用&#34替换XX; \ n"或"< BR>"或类似的东西,如果我使用这个功能仍然得到像
的输出"something something something"
而不是
something
something
something
答案 0 :(得分:2)
使用innerHTML
代替textContent
为我解决了这个问题(作为新行,请使用<br>
):
localStorage.history = localStorage.history +"something"+"<br>";
document.getElementById('history').innerHTML = localStorage.history;