add.js 435 B

1234567891011121314151617181920212223
  1. <html>
  2. <body>
  3. <script>
  4. // 创建一个h1元素
  5. var h1Element = document.createElement("h1");
  6. // 设置h1元素的文本内容
  7. h1Element.textContent = "火元素";
  8. // 设置h1元素的颜色为红色
  9. h1Element.style.color = "red";
  10. // 将h1元素添加到body元素中(你也可以选择添加到其他合适的父元素里)
  11. document.body.appendChild(h1Element);
  12. </script>
  13. </body>
  14. </html>