js code" statement; 2. Write the code into an external JavaScript file and embed it using the src attribute of the script tag; 3. Set the value of the event attribute in the HTML tag It is a code in the form of "JavaScript:xxx"."/> js code" statement; 2. Write the code into an external JavaScript file and embed it using the src attribute of the script tag; 3. Set the value of the event attribute in the HTML tag It is a code in the form of "JavaScript:xxx".">

Home  >  Article  >  Web Front-end  >  What are the ways to embed JavaScript into web pages?

What are the ways to embed JavaScript into web pages?

青灯夜游
青灯夜游Original
2021-10-25 18:03:257410browse

Embedding method: 1. Use the "<script>js code</script>" statement; 2. Write the code into an external JavaScript file and embed it using the src attribute of the script tag; 3. In HTML In the tag, set the value of the event attribute to a code in the form of "JavaScript:xxx".

What are the ways to embed JavaScript into web pages?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

3 ways to embed JavaScript into web pages

1. Use <script>.…</script> tag pair

Write the js code directly in the script tag pair. The script tag can be written in either the head tag or the body tag. Note:

##If the JavaScript code is placed in the tag: it is mainly used to complete what is needed Background task

##If the JavaScript code is placed in the tag: used to display content.

What are the ways to embed JavaScript into web pages?
#2. Introduce external JavaScript files

##This method is generally used in corporate work, because it ensures that the js code and html code are independent and have little mutual interference (low coupling).

What are the ways to embed JavaScript into web pages?
#mylife.js file is as follows: Write the js code directly, and the <script>.…</script>b tag pair must not appear in the js file!

What are the ways to embed JavaScript into web pages?
#3. Pseudo URL introduction

##This method generally appears in the format of "JavaScript: XXXXX", followed directly by the js code.

What are the ways to embed JavaScript into web pages?#[Recommended learning: javascript advanced tutorial
]

The above is the detailed content of What are the ways to embed JavaScript into web pages?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn