Where JavaScript scripts are placed
The javascripts in the HTML body section is executed when the page is loaded.
The javascripts in the HTML Head section is executed when it is called.
——————————————————————————
Scripts in the head section: scripts that need to be invoked to execute or events that trigger execution are placed in the head section of the HTML. When you put the script in the Head section, you can ensure that the script is loaded before any calls.
Script in the body section: the script that executes when the page is loaded is placed in the body part of the HTML. The script placed in the body section is often used to generate the contents of the page.
The body and head sections can have scripts at the same time: You can put countless scripts in the file, so your files can have scripts in both the body and head sections.
———————————————————————————–
Use of external scripts
Sometimes you might want to run the same script on several pages without having to write the code repeatedly on each page. You'll need to use an external script. You can write the script in an external file and save it in a file with a. js extension.
Note: Do not include the tag in the external script file <script>!
When using an external script, point the "src" attribute value of the marker <script> to the corresponding. js file:
Note: Remember that this script tag that points to an external script file is placed where you would normally write scripts!
1: Place the JavaScript identifier in the
2: Put the HTML head, is the page loaded before the run, put into the body, then load the code to run JavaScript ~ ~ ~
So the head inside is executed first.
3: If there is no difference in function if the <script>alert (1) </script> will follow the position of a matter of the head loaded on the alert one is to follow the body to load sequential alert
Client script is typically placed between
If the browser does not support this script, then the browser will
Skipping it, not executing it, and not making an error message
The difference between the head and body of JavaScript (the proposal is placed in the head tag)