js中write()和writeln()的区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WinstonLau/article/details/88574542
  • writeln() 相比 write() 多了一个换行符,但这个换行符在网页中是不会显示出换行的效果的,而是显示的一个空格
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>
</head>
<body>
<script>
    document.writeln("writeln");
    document.writeln("writeln");
</script>
</body>
</html>

在浏览器中显示的效果如下:
在这里插入图片描述

  • 如果想在浏览器中看到换行的效果,可以使用预格式标签
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>
</head>
<body>
<script>
    document.writeln("<pre>writeln");
    document.writeln("writeln</pre>");
</script>
</body>
</html>

在浏览器中显示的效果如下:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/WinstonLau/article/details/88574542
今日推荐