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

What are the ways to embed JavaScript into web pages?

青灯夜游
Release: 2021-10-25 18:03:25
Original
7517 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template