Javascript basic tutorial: The location of js code in the web page

We can place JavaScript code anywhere in the html file, but we usually place it in the head or body part of the web page.
Put it in the part
The most common way is to place the

In this way, our js code is placed in the head tag

It can also be placed in the body, as shown below

   javascript 

Note : JavaScript as a scripting language can be placed anywhere in the HTML page, but when the browser interprets the HTML, it is in order, so the previous script will be executed first. For example, the js for page display initialization must be placed in the head, because the initialization must be done in advance (such as setting css for the page body, etc.); and if the function is executed through an event call, there is no requirement for the location.

Let’s take a look at the format of js code

Note: document.write is the output statement, we will talk about it later

Continuing Learning
||
javascript
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!