javaScript knowledge points inductive

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
image
(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
image
2, placed in an external file
image
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
image

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
image
<!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
imageClick a tag pop
image
Click OK after the pop-up
image



Guess you like

Origin www.cnblogs.com/pere/p/11621980.html