" statement to introduce it; 2. Write js code in the script tag; 3. Write the js code externally js file, and then use the src attribute of the script tag to introduce it."/> " statement to introduce it; 2. Write js code in the script tag; 3. Write the js code externally js file, and then use the src attribute of the script tag to introduce it.">

Home  >  Article  >  Web Front-end  >  What are the ways to introduce JavaScript?

What are the ways to introduce JavaScript?

青灯夜游
青灯夜游Original
2021-06-11 18:17:5713136browse

There are three ways to introduce JavaScript: 1. Use the "025c7b3a9cc8b7a1a5d14e2942f1e26616bbdd474e7e1f7f182b48c374bef73a" statement to introduce; 2. Write js in the script tag Code; 3. Write the js code in an external js file, and then introduce it using the src attribute of the script tag.

What are the ways to introduce JavaScript?

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

There are three ways to introduce JavaScript:

1. Inline introduction:

<开始标签 on+事件类型=“js代码”></结束标签>

Inline introduction methods must be combined Events are used, but internal js and external js can not be combined with events

<body>
<input type="button" onclick="alert(&#39;行内引入&#39;)" value="button" name="button">
<button 0nclick="alert(123)">点击我</button>
</body>

2. Internal introduction:

In the head or body, define the script tag, and then in Write js code in the script tag

    3f1c4e4b6b16bbbd69b2ee476dc4f83a
        alert("这是js的内部引入");
    2cacc6d41bbb37262a98f745aa00fbf0

3. External introduction:

Define external js file (file ending in .js)

<script type=“text/javascript” src=“demo.js”>

Note:

  • script tags are generally defined in the head or body

  • Script tags should be used alone, either by introducing external js or by defining internal js. Do not Mix and match

external JS files, which have the characteristics of high maintainability, cacheability (load once, no need to load), convenient future expansion, and high reusability

Create a new external js file demo.js file

In the head or body, add the following code

<script  type="text/javascript" src="js/demo.js"></script>

The priority order of js execution is based on the order in the code.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of What are the ways to introduce JavaScript?. 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