1、script标签中
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
alert("script标签中");
</script>
</head>
<body>
</body>
</html>
执行结果:
2、标签属性中
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<label onclick="javascript:alert('标签属性中')">点击我</label>
</body>
</html>
执行结果:
3、js文件中
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script type="text/javascript" src="js/index.js" ></script>
</body>
</html>
<!--以下是js文件内容-->
alert("js文件中");
执行结果: