How to put the JavaScript function into the body section
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.