js code"; 2. Write the js code into a ".js" file and use "" statement can be used to introduce the js file."/> js code"; 2. Write the js code into a ".js" file and use "" statement can be used to introduce the js file.">

Home  >  Article  >  Web Front-end  >  How to connect html to js

How to connect html to js

青灯夜游
青灯夜游Original
2021-07-01 11:49:0413378browse

Method: 1. Directly embed the js code into the script tag pair with the syntax "3f1c4e4b6b16bbbd69b2ee476dc4f83ajs code2cacc6d41bbb37262a98f745aa00fbf0"; 2. Write the js code into a ".js" file, Use the "6fe72667dc91a8b20b2098e5c999b5c02cacc6d41bbb37262a98f745aa00fbf0" 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>

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>

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>
<html>
    <head>
        <title>World</title>
        <style type="text/css">
        </style>
    </head>
    <body>
        <script type="text/javascript" src="1.js">
            //alert("bbbbb");  没有效果
        </script>
    </body>
</html>

[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!

Statement:
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