Javascript HTML 未读取 %0A
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31690180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML not reading %0A
提问by Amadan
I have this code:
我有这个代码:
elf='%0A';
document.getElementById('writebox').innerHTML=("hello there"+elf+"friend");
When the function that this is inside is called, the text that appears in the div is not a line break, but rather just "%0a". This confuses me, because inside another different function, elf works fine. Any ideas why?
当调用 this 内部的函数时,出现在 div 中的文本不是换行符,而只是“%0a”。这让我很困惑,因为在另一个不同的函数中,elf 工作正常。任何想法为什么?
回答by Amadan
Different encoding. %0A
is URL-encoding of a newline, which you would use in (obviously) URLs. &x0a;
would be the HTML-encoding of the same character that you would use in HTML, but it doesn't work, for a variety of reasons. To break a line in HTML, you can use <br>
tag.
不同的编码。%0A
是换行符的 URL 编码,您将在(显然)URL 中使用它。&x0a;
将是您将在 HTML 中使用的相同字符的 HTML 编码,但由于各种原因,它不起作用。要在 HTML 中换行,您可以使用<br>
tag。
EDIT:
编辑:
the problem wit a
<br />
tag is that all i want is simply a new line.<br />
creates WAY too much white space
<br />
标签的问题是我想要的只是一个新行。<br />
创造了太多的空白
No, it doesn't:
不,它不会:
foo<br>
bar