运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗色/亮色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The appendChild() Method</h2> <ul id="myList"> <li>Coffee</li> <li>Tea</li> </ul> <p>Click "Append" to append an item to the end of the list:</p> <button onclick="myFunction()">Append</button> <script> function myFunction() { // Create an "li" node: const node = document.createElement("li"); // Create a text node: const textnode = document.createTextNode("Water"); // Append the text node to the "li" node: node.appendChild(textnode); // Append the "li" node to the list: document.getElementById("myList").appendChild(node); } </script> </body> </html>