6.JS输出

JavaScript 通常用于操作 HTML 元素。

 

① document.getElementById(id),可以访问某个 HTML 元素

   请使用 "id" 属性来标识 HTML 元素:

   通过指定的 id 来访问 HTML 元素,并改变其内容:

② document.write() 仅仅向文档输出写内容。

   ※如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖:

   

 实例

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<p>My First Paragraph.</p>

<button onclick="myFunction()">点击这里</button>

<script>
function myFunction()
{
document.write("糟糕!文档消失了。");
}
</script>

</body>
</html>
原文地址:https://www.cnblogs.com/jiningning/p/6385943.html