1.创建code.html,基本框架如下:
<html>
<head>
<title> Mine </title> <!--网页名称-->
</head>
<body>
<script>document.write("Hello!");</script> <!--基本代码,网页上输出hello-->
</body>
</html>
2.编写 js脚本
//script.js
document.write("Hello!");
<!--code.html-->
<html>
<head>
<title> Mine </title> <!--网页名称-->
</head>
<body>
<script src="code.js"></script> <!--调用js脚本,在网页上输出hello-->
</body>
</html>
3.上述两段代码实现的内容相同。
本文介绍了如何使用HTML和JavaScript在网页上输出简单的文本信息。通过两个示例代码,展示了直接在HTML文件中使用内联JavaScript与引入外部JavaScript文件两种方式来实现相同的功能。
1万+

被折叠的 条评论
为什么被折叠?



