JavaScript document方法2

用js代码创建html标签

appendChild方法可以向一个标签中添加子标签

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        window.onload = function () {
            var divObj = document.createElement("div");
            divObj.innerHTML = "子涵真帅";
            document.body.appendChild(divObj);
        }
    </script>
</head>
<body>

</body>

documen.creatTextNode 创建文本节点

            document.body.appendChild(document.createElement("br"));

            document.body.appendChild(document.createTextNode("子涵真帅"));

 

posted @ 2022-03-20 08:32  软工小蜗牛  阅读(88)  评论(0编辑  收藏  举报