HTML 未读取 %0A

HTML not reading %0A

我有这个代码:

elf='%0A';
document.getElementById('writebox').innerHTML=("hello there"+elf+"friend");

调用 this 所在的函数时,div 中出现的文本不是换行符,而是“%0a”。这让我很困惑,因为在另一个不同的函数中,elf 工作正常。有什么想法吗?

编码不同。 %0A 是换行符的 URL 编码,您将在(显然)URL 中使用它。 &x0a; 将是您将在 HTML 中使用的同一字符的 HTML 编码,但由于多种原因,它不起作用。要在 HTML 中换行,您可以使用 <br> 标签。

编辑:

the problem wit a <br /> tag is that all i want is simply a new line. <br /> creates WAY too much white space

不,它没有:

foo<br>
bar