Javascript scripts can be placed in: 1. In the body part of HTML, JavaScripts scripts will be executed when the page is loaded; 2. In the head part of HTML, JavaScripts scripts will be executed when called.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Location of javascript script:
HTML body part, JavaScripts will be executed when the page is loaded.
In the HTML head part, JavaScripts will be executed when called.
Note: The JavaScripts in the
page will be executed immediately when the browser loads the page. We do not want this to always be the case. Sometimes we want a script to be executed when the page loads, and sometimes we want to execute the script when the user triggers an event.
Scripts in the head section: Scripts that need to be called to be executed or scripts that are triggered by events are placed in the head section of HTML. When you place a script in the head section, you ensure that the script is loaded before any calls are made.
【Related recommendations: javascript learning tutorial】
The above is the detailed content of Where to put the javascript script. For more information, please follow other related articles on the PHP Chinese website!