Call external JS in HTML through the following steps: Create a JS file and write code. Add the <script> tag to the HTML code and set the src attribute to the JS file path. Save and refresh the page to load the external JS.
How to call external JS in HTML
HTML is a markup language used to structure the website and content. And JavaScript (JS) is a scripting language that adds interactivity and dynamic behavior to websites. To call an external JS file, you need to use the <script>
tag in the HTML code.
Steps:
.js
file in a text editor, and Write the required JavaScript code. <script>
tag in the HTML code: In <head>
or <body>
Add the following code to the section: <code class="html"><script src="path/to/my-script.js"></script></code>
Please replace path/to/my-script.js
with the actual path to the JS file.
src
Attribute: The src
attribute specifies the URL or path of the JS file to be loaded. Note:
<script># in the
<head> or
<body> section ## Label.
tag in
<head> to load JS when the page loads, or you can put it in
in so that the JS is loaded after the content is loaded.
The above is the detailed content of How to call external js in html. For more information, please follow other related articles on the PHP Chinese website!