-
Learning Web site (backing people): HTTPS: //www.houdunren.com/
b station video: https: //www.bilibili.com/video/av80536021 -
Js introduced in two ways:
1. the introduction of external files:
introducing external js file by setting the src attribute.
Introduced 1.js contents of the file:
alert(3);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js练习</title>
</head>
<body>
你好
<script src="1.js"></script>
</body>
</html>
Note:
① when introducing an external file, the script does not execute in the body of the label.
Test: the introduction of 1.js contents of the file:
alert(3);
**html**文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js练习</title>
<script src="1.js">
alert('666.com');
</script>
</head>
<body>
</body>
</html>
② generally placed rearmost content, avoid delays: If the label on the loaded first resolve js, then will display the contents label.
Test code: introduced 1.js contents of the file:
alert(3);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js练习</title>
</head>
<body>
你好
<!-- <script src="1.js"></script> -->
<!-- 将其放在<head>标签体内与放在此处作比较 -->
</body>
</html>
Results:
2. embedded script (rarely used)
like style tags, you can use the script tag javascript code embedded in html document.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js练习</title>
</head>
<body>
你好
<script>
alert("consistent")
</script>
</body>
</html>