In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to put javascript script in Html", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to put javascript script in Html" article.
Javascript scripts can appear in two locations, namely: 1, in the HTML body section, the location of the js will be executed when the page is loaded; 2, in the HTML head section, the location of the js will be called when the execution.
This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.
The location of the JS script in Html
Where do I put the JavaScript script?
The JavaScripts in the HTML body section is executed when the page is loaded.
The JavaScripts in the HTML head section is executed only when it is called.
-
Where should JavaScript be put?
The JavaScripts in the page is executed immediately when the browser loads the page, and we don't want this to be always the case. Sometimes we want a script to be executed when the page is loaded, 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 execute or scripts 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 call.
... .
Scripts in the body section: scripts that are executed when the page is loaded are placed in the body section of the HTML. Scripts placed in the body section are often used to generate the content of the page.
... .
Body and head can have scripts at the same time: you can put countless scripts in the file, so you can have scripts in both the body and head parts of your file.
... .. .
-
Use of external scripts
Sometimes you may want to run the same script on several pages without having to write the code repeatedly on each page. This is when you 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 tags in external script files!
When using an external script, point the value of the "src" property of the tag to the appropriate .js file:
The above is about the content of this article on "how to put javascript scripts in Html". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.