"; 3. External js, written in another inside a file."/> "; 3. External js, written in another inside a file.">

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

What are the writing positions in JavaScript?

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-16 14:41:034703browse

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

2. Embedded js

Write into <script></script>

1. Embed into

Need to write an entry function

window.onload=function(){

}

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!

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