簡體   English   中英

如何將本地 js 文件導入基本 html 文件?

[英]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. 我如何錯誤地格式化腳本標簽?

文件夾結構

-folder
  --test.html
  --script.js

測試.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>

腳本.js

console.log('HELLO WORLD')

(function () {
  setTimeout(() => alert('HELLO WORLD'), 3000)
})();

您應該在單獨的標簽中關閉您的腳本標簽:

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

您的腳本標簽不正確,應該是: <script type='text/javascript' src="script.js"></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM