内部
clike
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
alert("你好")
</script>
</body>
</html>
外部
clike
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./外部.js"></script>
</body>
</html>
行内
clike
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 onclick="alert('丘丘')">锄禾日当午</h1>
</body>
</html>
- 不管是内部的还是外部的,书写的位置都尽量写到文档末尾前面
- 外部Js标签中间不要写代码,否则会被忽略