Javascript can be written in the body. Write the Javascript code in the "" tag pair through the script tag. When the browser loads the Body part of the web page, it will execute the Javascript statement in it, and the output content after execution will be displayed on the web page.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The placement location of Javascript:
Html web page
;Html The webpage's
;##Javascript is written in
When the browser loads the Body part of the web page, it executes the Javascript statements in it, and the output content after execution is displayed on the web page.<html> <head></head> <body> <script type="text/javascript">....</script> </body> </html>
Javascript is written in
Sometimes it is not necessary to run Javascript as soon as the HTML is loaded, but when the user clicks When an object in HTML triggers an event, Javascript needs to be called. At this time, such Javascript is usually placed in of HTML.<html> <head> <script type="text/javascript">....</script> </head> <body> </body> </html>
<html> <head></head> <body> </body> <script type="text/javascript">....</script> </html>
The difference between js code written after body, head and body
The computer reads the code The order is read from top to bottom. The order in the html file is →→behind bodyjavascript advanced tutorial]
The above is the detailed content of Can javascript be written in the body?. For more information, please follow other related articles on the PHP Chinese website!