JavaScript 显示方案
使用 window.alert() 写入警告框
实例
<html>
<body>
<h1>我的第一张网页</h1>
<p>我的第一个段落</p>
<script>
window.alert("这是一个警告框");
</script>
</body>
</html>
使用 document.write() 写入 HTML 输出
实例
<html>
<body>
<h1>我的第一张网页</h1>
<p>我的第一个段落</p>
<script>
document.write("这是使用document.write()方法显示出来的字符");
</script>
</body>
</html>
使用 innerHTML 写入 HTML 元素
实例
<html>
<body>
<h1>我的第一张网页</h1>
<p>我的第一个段落</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 这是使用document.getElementById(id)方法显示的字符;
</script>
</body>
</html>
使用 console.log() 写入浏览器控制台
实例
<html>
<body>
<h1>我的第一张网页</h1>
<p>我的第一个段落</p>
<script>
console.log("此信息不会出现在HTML页面中,而是出现在控制台上");
</script>
</body>
</html>