<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- js写到外部js文件中,通过script标签进行引入 -->
<script src="./script.js"></script>
<!-- _________________________________________ -->
<!-- 错误示范 -->
<!-- <script src="./script.js">
alert("你好");
</script> -->
<!-- _________________________________________ -->
<!-- js写到script标签中 -->
<script>
// alert("你好");
</script>
</head>
<body>
<!-- 以下两种情况不方便维护(结构与行为耦合),特殊情况下书写 -->
<!-- 可以将js代码写到标签的onclick属性中,当点击按钮时将会执行 -->
<button onclick="alert(‘hello world‘)">点我一下</button>
<!-- 可以将js写到超链接href属性中,当点击时将会执行 -->
<a href="javascript:alert(‘hello‘)">点我</a>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- js书写位置 -->
<script>
// 控制浏览器弹出警告框
alert("hello world");
// 在计算机页面输出一个内容
document.write("hello world");
// 在控制台输出一个内容
console.log("hello world");
</script>
</head>
<body>
</body>
</html>