Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Where can I write the javascript code

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces where the javascript code can be written, the article is very detailed, has a certain reference value, interested friends must read it!

Javascript code can be written in: 1, using the script tag, written in the Body section of the Html page; 2, using the script tag, written in the head section of the Html page; 3, written in the suffix name ".js" in the text file, and using the src attribute of the script tag to introduce the Html page.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Where does Javascript write? It can be summed up in three forms:

Internal: in the Body of the Html page

Internal: in the head of the Html page

External: in external JS files.

1. Javascript is written in Body

When the browser loads the Body part of the web page, the Javascript statement is executed, and the output is displayed in the web page after execution.

.. Javascript code..

2. Javascript is written in head

Sometimes instead of running Javascript as soon as the HTML is loaded, the user clicks on an object in the HTML and triggers an event before calling Javascript. At this time, such a Javascript is usually placed in the head of HTML.

.. Javascript code..

3. Javascript is written in an external js file

Put the Javascript program in a text file with the suffix .js.

If you refer to Javascript in an external file in HTML, you should write a sentence in Head, where the value of src is the file path of the file where Javascript is located. The sample code is as follows:

...

Script in head: a script that needs to be called for execution or a script that is triggered by an event. When a script is placed in head, it is guaranteed that the script will be loaded before any call.

Script in body: a script that is executed when a page is loaded, usually used to generate the content of the page.

The above is all the contents of the article "where can the javascript Code be written?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report