Home > Web Front-end > HTML Tutorial > How to call external js in html

How to call external js in html

下次还敢
Release: 2024-04-11 12:31:20
Original
495 people have browsed it

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

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:

  1. Create JS file: Create the .js file in a text editor, and Write the required JavaScript code.
  2. Add the <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>
Copy after login

Please replace path/to/my-script.js with the actual path to the JS file.

  1. Settings src Attribute: The src attribute specifies the URL or path of the JS file to be loaded.
  2. Save and Refresh: Save the HTML file and refresh the page to load the external JS.

Note:

  • Make sure that the HTML and JS files are on the same server, or have appropriate cross-domain access permissions.
  • Can call multiple external JS files, just add additional <script># in the <head> or <body> section ## Label.
  • You can put the
  • <script> 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.
  • External JS must be written in legal JavaScript syntax.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template