0
点赞
收藏
分享

微信扫一扫

自学JavaScript--------js输出的四种方式

源码之路 2022-01-20 阅读 46

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>
举报

相关推荐

0 条评论