W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>单击该按钮可创建包含 H1 和 P 元素的 ARTICLE 元素。</p> <button onclick="myFunction()">试一试</button> <script> function myFunction() { var x = document.createElement("ARTICLE"); x.setAttribute("id", "myArticle"); document.body.appendChild(x); var heading = document.createElement("H1"); var txt1 = document.createTextNode("Heading in Article"); heading.appendChild(txt1); document.getElementById("myArticle").appendChild(heading); var para = document.createElement("P"); var txt2 = document.createTextNode("Paragraph in article."); para.appendChild(txt2); document.getElementById("myArticle").appendChild(para); } </script> </body> </html>