2 methods and precautions for adding scripts in HTML

2 methods and precautions for adding scripts in HTML
How to add <script> script in HTML:

1. You can directly add javascript code to html

Copy code
The code is as follows:

<script type="text/javascript">
//javascript code
</script>

When the interpreter embeds <script> code, the processing of the HTML page will also be temporarily stopped.

2. Add external js files

Copy code
The code is as follows:

<script type="text/javascript" src="Address of external .js code"></script>

Note:
① In XHTML documents, the </script> tag can be omitted, for example:

Copy code
The code is as follows:

<script type="text/javascript" src="example.js" />

However, the </script> tag cannot be omitted in HTML. This tag does not comply with HTML specifications and therefore cannot be correctly parsed by some browsers.

② It is best to put the <script> tag before the </body> tag, which will enable the browser to load the page faster.

③When using <script> to embed JavaScript code, do not allow the “</script>” string to appear anywhere in the code. For example, a browser will generate an error when loading the following code:

Copy code
The code is as follows:

<script type="text/javascript">
function function1(){
alert("</script>");
}

Because according to the rules for parsing embedded code, when the browser encounters the string "</script>", it will think that it is the closing </script> tag. If you want to add a </script> string to the code, you can write it as <\/script>

<<:  Two ways to build a private GitLab using Docker

>>:  How to create a simple column chart using Flex layout in css

Recommend

Improvement experience and sharing of 163 mailbox login box interactive design

I saw in the LOFTER competition that it was mentio...

MySQL permission control details analysis

Table of contents 1. Global level 2. Database lev...

Detailed installation instructions for the cloud server pagoda panel

Table of contents 0x01. Install the Pagoda Panel ...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...

How to build svn server in linux

1: Install SVN yum install -y subversion 2. Creat...

How to create a virtual environment using virtualenv under Windows (two ways)

Operating system: windowns10_x64 Python version: ...

Detailed explanation of Vue's caching method example

Recently, a new requirement "front-end cache...

Summary of basic usage of js array

Preface Arrays are a special kind of object. Ther...

The whole process of developing a Google plug-in with vue+element

Simple function: Click the plug-in icon in the up...

Record a pitfall of MySQL update statement update

background Recently, I executed a DML statement d...

Nginx monitoring issues under Linux

nginx installation Ensure that the virtual machin...

MySQL 5.6.27 Installation Tutorial under Linux

This article shares the installation tutorial of ...

Solution to Docker's failure to release ports

Today I encountered a very strange situation. Aft...

Steps for importing tens of millions of data into MySQL using .Net Core

Table of contents Preliminary preparation Impleme...