"; 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?
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.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
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!