三种引入方式

  • 1、在元素的事件属性中添加js代码,当事件触发时js执行

  • 2、内部: 在html页面中任意位置添加script(推荐head里面)

  • 3、外部: 在单独的js文件中写js代码,通过script的src属性引入,如果script标签引入了文件则不能在标签体内继续写js代码



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<!-- 内部引入方式-->
<script type="text/javascript">
alert("使用内部引入");

var x = "123";
if(isNaN(x)){
alert("不是数");
}else{
alert("是数");
}

</script>

<!-- 外部引入方式-->
<script type="text/javascript" src="first.js"></script>
</head>

<body>
<!-- 内联方式-->
<input type="button" value="内联引入方式"
onclick="alert('内联引入方式')">
</body>

</html>