Get the App
SLTechnology News&Howtos  ›  Development  › 

How to put the JavaScript function into the body section

Shulou Source: shulou.com Published: 2022-06-01 12:02:54 09月14日 Update

This article mainly introduces the relevant knowledge of "how to put the JavaScript function into the body part". The editor shows you the operation process through the actual case, the operation method is simple and fast, and the practicality is strong. I hope this article "how to put the JavaScript function into the body part" can help you solve the problem.

JavaScript function in

In this example, we put a JavaScript function in the section of the HTML page.

This function is called when the button is clicked:

Example

My Web page

A paragraph

Give it a try

FunctionmyFunction ()

{

Document.getElementById ("demo") [xss_clean] = "my first JavaScript function"

}

External JavaScript

You can also save the script to an external file. External files usually contain code used by multiple web pages.

The file extension of the external JavaScript file is .js.

To use an external file, set the .js file in the "src" attribute of the tag:

Example

You can place the script in or, and the script in the tag runs exactly the same as the externally referenced script.

The myScript.js file code is as follows:

FunctionmyFunction ()

{

Document.getElementById ("demo") [xss_clean] = "my first JavaScript function"

}

Lamp external scripts cannot contain tags.

This is the end of the introduction to "how to put the JavaScript function into the body section". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Functions files scripts parts tags knowledge code examples industries pages different practical consistent content multiple practical actual properties extensions buttons Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL vpn Redmi Shulou Information