How to connect html to js

青灯夜游
Release: 2021-07-01 11:49:04
Original
13382 people have browsed it

Method: 1. Directly embed the js code into the script tag pair with the syntax "<script>js code</script>"; 2. Write the js code into a ".js" file, Use the "" statement to introduce the js file.

How to connect html to js

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

There are two ways to combine (connect) js and HTML

The first one: directly embed the js code into the script tag pair Medium

Grammar

<script type="text/javascript"> js代码; </script>
Copy after login

Second: Use the script tag to introduce an external js file

*** Create a js file , write js code

*** and then use the following statement to introduce

<script type="text/javascript" src="js文件路径"></script>
Copy after login

When using the second method, do not write js code in the script tag, as it will not be executed.

Example:

<html>
    <head>
        <title>World</title>
        <style type="text/css">
        </style>
    </head>
    <body>
        <script type="text/javascript">
            alert("aaaaaa");
        </script>
    </body>
</html>
Copy after login
<html>
    <head>
        <title>World</title>
        <style type="text/css">
        </style>
    </head>
    <body>
        <script type="text/javascript" src="1.js">
            //alert("bbbbb");  没有效果
        </script>
    </body>
</html>
Copy after login

[Related recommendations: javascript learning tutorial]

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

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template