I have a very basic html file that uses a script tag to import a javascript file, but the javascript file is not run when I load the html locally in a browser. How am I formatting the script tag incorrectly?
Folder Structure
-folder
--test.html
--script.js
test.html
<html lang="en">
<head>
<meta charset="utf-8">
<title>TEST</title>
</head>
<body>
<p>TEST</p>
<script type='text/javascript' src="script.js" />
</body>
</html>
script.js
console.log('HELLO WORLD')
(function () {
setTimeout(() => alert('HELLO WORLD'), 3000)
})();
You should close your script tag in a separate tag:
<script type="text/javascript" src="script.js"></script>
Your script tag is incorrect it should be: <script type='text/javascript' src="script.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.