运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,暗色/亮色
转到 Spaces
<!DOCTYPE html> <html> <body> <p>Click the button to create an ARTICLE element containing a H1 and P element.</p> <button onclick="myFunction()">Try it</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>