""/> "">
Home >Web Front-end >HTML Tutorial >How to add js to html
Method: 1. Embed JavaScript code in the script tag of the html page; 2. Write the js code in a ".js" file, and then introduce the external js file through the src attribute of the script tag, syntax "6fe72667dc91a8b20b2098e5c999b5c02cacc6d41bbb37262a98f745aa00fbf0"
The operating environment of this tutorial: windows7 system, javascript1.8.5&&HTML5 version , Dell G3 computer.
1. Embed JavaScript code in the script tag of the html page
Example:
<body> <script> var a=1; alert(a); </script> </body>
2. Through the src attribute of the script tag Introducing external js files
<body> <!-- 引入本地文件 --> <script src="./script.js"></script> <!-- 引入外部域的文件 --> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </body>
In this way, the server will send the JavaScript file to the browser with the MIME type application/x-javascript.
Note:
Although the 3f1c4e4b6b16bbbd69b2ee476dc4f83a tag has many other attributes, these attributes are not commonly used, or they all have default values, and these default values usually do not need to be changed, so The src attribute is probably the only attribute you need to know about.
Recommended tutorial: "html video tutorial"
The above is the detailed content of How to add js to html. For more information, please follow other related articles on the PHP Chinese website!