Home > Web Front-end > HTML Tutorial > How to add js to html

How to add js to html

青灯夜游
Release: 2023-01-06 11:13:19
Original
17542 people have browsed it

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 ""

How to add js to html

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>
Copy after login

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>
Copy after login

In this way, the server will send the JavaScript file to the browser with the MIME type application/x-javascript.

Note:

Although the

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template