刚刚开始接触JavaScript时,根本就不知道该如何下手,甚至也不知道该利用什么工具来写,以下是我总结出的两种JavaScript代码的写法。
- 内部引入:在html文件中的head标签之间或者是body标签之间(如果在body标签中写则通常放在body部分的后面)中写。
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js</title>
<script>
alert('hello,world');//弹出窗口
</script>
</head>
<body>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js</title>
</head>
<body>
<script>
alert('hello,world');//弹出窗口
</script>
</body>
</html>
- 外部引入:新建一个.js文件,然后在.html文件中链接.js文件
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Js</title>
<!--外部引入-->
<!--注意script标签必须成对出现-->
<script src="hello.js"></script>//必须要注意路径,此处为相对路径
</head>
<body>
</body>
</html>
alert('hello world!');//.js文件,弹窗对话