JavaScript 四种显示数据方式

2023-06-20,,

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript 显示数据</title>
<style type="text/css">
p{
background-color: yellow;
}
</style>
<script> window.onload=function () {
// 方式1:使用window.alert()弹出警告框
alert('hello,My name is Apollo !'); // 方式2:使用document.write()方法将内容写到HTML文档中
// document.write('hello,My name is Apollo !'); // 方式3:使用innerHtml方法写入到Html元素中去
// 1.JS入口函数有一个覆盖现象,假如你不注释上面document.write()相关代码,下面代码是看不见的.
// 2.使用getElementsByTagName必修要加上索引,因为p标签很多,你这样得到的是一个数组
// document.getElementsByTagName('p')(0).innerHTML='hello,My name is Apollo !!!'; // 方式4使用console.log()控制台输出
console.log('hello,My name is Apollo !');
} </script>
</head>
<body>
<div>
<p>这里的代码将会被替换......</p>
<p>这里是第二个p标签</p>
</div>
</body>
</html>

JavaScript 四种显示数据方式的相关教程结束。

《JavaScript 四种显示数据方式.doc》

下载本文的Word格式文档,以方便收藏与打印。