Home >Web Front-end >Front-end Q&A >Where to put the javascript script

Where to put the javascript script

青灯夜游
青灯夜游Original
2021-06-30 17:42:282596browse

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.

Where to put the javascript script

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!

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