1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <title>输出--显示</title>
8 </head>
9 <body>
10 <!--
11 JavaScript 显示方案
12 JavaScript 能够以不同方式“显示”数据:
13
14 1.使用 innerHTML 写入 HTML 元素
15 2.使用 document.write() 写入 HTML 输出
16 3.使用 window.alert() 写入警告框
17 4.使用 console.log() 写入浏览器控制台
18 -->
19 <h1>我的第一张网页</h1>
20
21 <p>我的第一个段落</p>
22
23 <p id="demo"></p>
24
25 <!--在 HTML 文档完全加载后使用 document.write() 将删除所有已有的 HTML -->
26 <button onclick="document.write(5 + 6)">试一试</button>
27
28 <script>
29 document.getElementById("demo").innerHTML = 5 + 6;//1.更改 HTML 元素的 innerHTML 属性是在 HTML 中显示数据的常用方法
30
31 document.write(5 + 6);//2.document.write() 方法仅用于测试。
32
33 alert(5 + 6);//3.您能够使用警告框来显示数据
34
35 console.log(5 + 6);//4.在浏览器中,您可使用 console.log() 方法来显示数据。请通过 F12 来激活浏览器控制台,并在菜单中选择“控制台”
36 </script>
37 </body>
38 </html>