Home Web Front-end HTML Tutorial How to introduce js files into html

How to introduce js files into html

Apr 12, 2021 pm 06:07 PM
html js

Two import methods: 1. Use the src attribute of the script tag to import the js file, the syntax is "<script src="js file path"></script>". 2. Reference js files in JavaScript code with the syntax "script tag object.src = "file path";".

The operating environment of this tutorial: windows7 system, javascript1.8.5&&HTML5 version, Dell G3 computer.

js file refers to a text file that stores JavaScript code, with the suffix name ".js".

So how to introduce js files in html, there are the following two methods:

The first one: use the src attribute of the script tag to introduce js files

&lt;script type=&quot;text/javascript&quot; src=&quot;../js/jquery-1.8.3.js&quot;&gt;&lt;/script&gt;//(相对路径)
&lt;script src=&quot;http://common.cnblogs.com/script/jquery.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;//(绝对路径)
Copy after login

Second type:Referencing external js in JavaScript code

&lt;script&gt;
  window.onload = function(){
    var script = document.createElement(&quot;script&quot;);
    script.setAttribute(&quot;type&quot;,&quot;text/javascript&quot;);
    script.src = &quot;http://common.cnblogs.com/script/jquery.js&quot;;
    document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script);  
  }
&lt;/script&gt;
Copy after login

Recommended learning:html video tutorial

The above is the detailed content of How to introduce js files into html. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

Nested Table in HTML

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Table Border in HTML

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

HTML margin-left

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

HTML Table Layout

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Moving Text in HTML

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

HTML Ordered List

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

HTML onclick Button

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

How do you parse and process HTML/XML in PHP?

See all articles