Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

javascript - How do you import a local js file into a basic html file?

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)
})();
question from:https://stackoverflow.com/questions/65928106/how-do-you-import-a-local-js-file-into-a-basic-html-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should close your script tag in a separate tag :

<script type="text/javascript" src="script.js"></script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...