首页 > 解决方案 > js document.getElementByClassName("").appendChild(); 的问题

问题描述

    <!DOCTYPE html>
<html>
<head>
<script>
    function myFunction() {
                let exmpale = document.createElement("div");
                exmpale.innerHTML = "aaaaa";
                exmpale.className = "classDiv";
                document.getElementsByClassName("myDIV").appendChild(exmpale);
    }      
</script>
</head>
<body>

<div class="myDIV">
A DIV
</div>

<button onclick="myFunction()">button</button>
</body>
</html>

我不知道为什么,但是当我单击按钮时,它不会打印出innerHTML(aaaaa) 中的值。

标签: javascripthtmlclassdocumentappendchild

解决方案


推荐阅读