javascript document.writeln为什么没有换行

 我们知道document.writeln()会输出new line,可是在浏览器中我们查看时却始终没有换行:

document.writeln('hello');

document.writeln('world');

输出hello world.

实际上,document.writeln()是输出了new line的,只不过当浏览器在渲染renderinghtml时把新行显示为一个空格了。我们可以这样验证:

document.write('<pre>');
document.writeln('hello');
document.writeln('world');
document.write('</pre>');

输出

hello

world

我们想要用document.write换行时可以用<br/>或\n。

原文地址:https://www.cnblogs.com/youxin/p/2687800.html