A, javascrit on which file
1, on the <script> tag
(1) immediate release
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
document.write("初学javascript")
document.write("<h1>hello javascript</h1>")
</script>
</body>
</html>
The result is code that runs
(2) then <script> tag in <div> tag
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>
<script type="text/javascript">
document.write("初学javascript")
document.write("<h1>hello javascript</h1>")
</script>
</div>
</body>
</html>
The result is the same code to run
2, placed in an external file
export.js file code:
/**
* Created by pere on 2019-10-04.
*/
document.write("初学javascript")
document.write("<h1>hello javascript</h1>")
test1 code:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="export.js"></script>
</head>
<body>
</body>
</html>
Operating results are
3, on the HTML tags
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" value="弹出消息" onclick="javascript:alert('欢迎你')">
</body>
</html>
Code running results: onlcick event
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<!--<script type="text/javascript" src="export.js"></script>-->
</head>
<body>
<a onclick="javascript:alert('欢迎你')" href="javascript:alert('a标签弹出')">a标签</a>
</body>
</html>
The results of running code
Click a tag pop
Click OK after the pop-up