Basic application methods of javascript embedded and external links

Basic application methods of javascript embedded and external links

Basic application of javascript embedded and external links

The js language can be completely placed in the html language

But depending on the situation, it can be divided into embedded and external links.

When there is less js code, you can directly use the embedded method to introduce javascript through the <script></script> tag and related attributes

<!DOCTYPE html>
<html>
<script>
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
</script>
<body>
 
</body>
</html>

However, in large projects and when there are a lot of javascript codes, you need to use external links.

When using external links, you need to create a new .js file first

<!DOCTYPE html>
<html>
<script type="text/javascript" src="1245.js">
</script>
<body>
 
</body>
</html>

Put the javascript code you need to write in the 1245.js file

Three ways to write JavaScript: inline, embedded, and externally linked

1. Inline

In the attributes of the HTML tag, the execution is triggered by the behavior. (Rarely used)

insert image description here

2. Embedded

Wrap it in the HTML file using a script tag and it will execute automatically when the page is opened. (It’s easy to use, but don’t use it with large amounts of JS code.)

insert image description here

3. External link

Written in a separate js file, introduced in the html file using the src attribute of the script tag, it will be automatically executed when the page is opened. (Recommended because there are various optimization methods)

insert image description here

insert image description here

Note : It is rarely used in the industry, almost never used. Inline and external links cannot share the same script tag. In principle, the script tag of the external link can be placed anywhere. The script attribute of the external link is src , not href, not href, not href...

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • JavaScript dynamically adds styles (inline/embedded/external link rules, etc.)
  • A simple way to get the external link style of an element in js
  • How to get the element's external link style in js

<<:  What is flex and a detailed tutorial on flex layout syntax

>>:  Two ways to solve the problem of MySQL master-slave database not being synchronized

Recommend

Solution for importing more data from MySQL into Hive

Original derivative command: bin/sqoop import -co...

How to implement paging query in MySQL

SQL paging query:background In the company's ...

Interpretation and usage of various React state managers

First of all, we need to know what a state manage...

JavaScript canvas to achieve raindrop effect

This article example shares the specific code for...

Vue+SSM realizes the preview effect of picture upload

The current requirement is: there is a file uploa...

MySQL intercepts the sql statement of the string function

1. left(name,4) intercepts the 4 characters on th...

Details on how to use class styles in Vue

Table of contents 1. Boolean 2. Expression 3. Mul...

CSS polar coordinates example code

Preface The project has requirements for charts, ...

How to use Celery and Docker to handle periodic tasks in Django

As you build and scale your Django applications, ...

Share some key interview questions about MySQL index

Preface An index is a data structure that sorts o...

Implementing simple tabs with js

Tab selection cards are used very frequently on r...

7 Best VSCode Extensions for Vue Developers

Adding the right VS Code extension to Visual Stud...

js canvas realizes rounded corners picture

This article shares the specific code of js canva...

Detailed explanation of the top ten commonly used string functions in MySQL

Hello everyone! I am Mr. Tony who only talks abou...