document.write的用处

document.write  -----能够直接在文档流中写入字符串

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<h1>dan</h1>
    <script>
        document.write('<p>Good boy dan</p>');
    </script>
    <h2>Name:dan</h2>
</body>
</html>

结果显示:======》
dan
Good boy dan

Name:dan

执行玩代码之后检查浏览器html会发现自动插入了P标签

原文地址:https://www.cnblogs.com/dingyutao/p/9145088.html