web前端之Javascript的输出

操作 HTML 元素

如需从 JavaScript 访问某个 HTML 元素,您可以使用 document.getElementById(id) 方法。

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

警告:

请使用 document.write() 仅仅向文档输出写内容。

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

程序演示:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title></title>
 6     </head>
 7     <body>
 8         <h1>this is a title</h1>
 9         <p>this is a paragrage</p>
10         <button type="button" onclick="myfunction()">点击这里</button>
11         <script type="text/javascript">
12             function myfunction(){
13                 document.write("槽糕,文档丢了!!");
14             }
15         </script>
16     </body>
17 </html>
原文地址:https://www.cnblogs.com/ztyy04126/p/4915808.html