How to introduce js files into html
Apr 12, 2021 pm 06:07 PMTwo 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
<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>//(相对路径) <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script>//(绝对路径)
Second type:Referencing external js in JavaScript code
<script> window.onload = function(){ var script = document.createElement("script"); script.setAttribute("type","text/javascript"); script.src = "http://common.cnblogs.com/script/jquery.js"; document.getElementsByTagName("head")[0].appendChild(script); } </script>
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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