Home > Web Front-end > JS Tutorial > What are the writing positions in JavaScript?

What are the writing positions in JavaScript?

醉折花枝作酒筹
Release: 2021-07-16 14:41:03
Original
4771 people have browsed it

There are three writing positions, namely: 1. Inline js, written directly into the element; 2. Inline js, written inside ""; 3. External js, written in another inside the file.

What are the writing positions in JavaScript?

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

Three writing positions of JS

1. Inline js

Write directly into the element

<input type="button"  value="点击" onclick="alert(1)" />
Copy after login

2. Embedded js

Write into <script></script>

1. Embed into

Need to write an entry function

window.onload=function(){

}
Copy after login

2. Embed it in or

3. Write external js

in another In the file

First create a new file with the suffix .js, and then add (not allowed in the middle of the tag) in the html code write the code).

Note

1. Double quotation marks are usually used in html, and single quotation marks are usually used in js

2. When writing a large amount of js code, it is recommended to use external js

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What are the writing positions in JavaScript?. 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