js 第一课

什么是JavaScript

JavaScript是一种脚本语言,运行在网页上。无需安装编译器。只要在网页浏览器上就能运行

一般JavaScript与HTML合作使用。

例如

<html>
<head></head>
<body>

<script>
alert("hello world!");
</script>

</body>
</html>

JavaScript一般放在script>……</script> 标签里。

JavaScript的文件放在哪里

1 直接放在head标签

例如

<html>
<head>
<script>
alert("hello world!");
</script>

</head>
<body>

</body>
</html>

2 放在body中

<html>
<head></head>
<body>

<script>
alert("hello world!");
</script>

</body>
</html>

3 放在外部文件中

直接把 JavaScript 代码写在 HTML 里,我们还可以把 JavaScript 的代码写在一个 js 文件中,在 HTML 里调用这个 js 文件。

代码保存并命名为“out.js”

alert("hello word!");

之后在html中调用

<html>
<head>
<h1> my JavaScript code in "out.js" </h1>
</head>

<body>

<script src="out.js"></script>

</body>

</html>
原文地址:https://www.cnblogs.com/wangshouchang/p/6640301.html