search
HomeWeb Front-endHTML TutorialHTML escape character table_html/css_WEB-ITnose

为什么要用转义字符串?

HTML中,&等有特殊含义(,用于链接签,&用于转义),不能直接使用。这些符号是不显示在我们最终看到的网页里的,那如果我们希望在网页中显示这些符号,该怎么办呢?

这就要说到HTML转义字符串(Escape Sequence)了。


转义字符串(Escape Sequence)也称字符实体(Character Entity)。在HTML中,定义转义字符串的原因有两个:第一个原因是像“”这类符号已经用来表示HTML标签,因此就不能直接当作文本中的符号来使用。为了在HTML文档中使用这些符号,就需要定义它的转义字符串。当解释程序遇到这类字符串时就把它解释为真实的字符。在输入转义字符串时,要严格遵守字母大小写的规则。第二个原因是,有些字符在ASCII字符集中没有定义,因此需要使用转义字符串来表示。


转义字符串的组成

转义字符串(Escape Sequence),即字符实体(Character Entity)分成三部分:

第一部分是一个&符号,英文叫ampersand;

第二部分是实体(Entity)名字或者是#加上实体(Entity)编号;

第三部分是一个分号。


比如,要显示小于号(

> & &符号 & & " 双引号 " " © 版权 © © ® 已注册商标 ® ® ? 商标(美国) ? ™ × 乘号 × × ÷ 除号 ÷ ÷

字符 十进制 转义字符
" " "
& & &
< <
> > >
不断开空格(non-breaking space)    

HTML special escape character comparison table Character decimal escape character Character decimal escape character Character Decimal escape character Ç È É Ê Ë Ì Í Ò Ó Ô Õ
? ¡ ¡ Á Á Á á á á
¢ ¢ Â Â ˆ â â â
£ £ Ã Ã Ã ã ã ã
¤ ¤ ¤ Ä Ä Ä ä ä ä
¥ ¥ Å Å ˚ å å å
| ¦ æ ; æ § § § Ç Ç
ç ç ç ¨ ¨ ¨ È È
è è è © © © É É
é é é a ª ª Ê Ê
ê ê ê ? « « Ë Ë
ë ë ë ? ¬ ¬ Ì Ì
ì ì ì /x7f ­ ­ Í Í
í í í ® ® î ® î
ˉ ¯ ¯ Ï Ï Ï ï ï ï
° ° ° Ð Ð Ð ð ð &ieth;
± ± ± ñ ; 2 ² ² Ò Ò
ò ò ò 3 ³ ³ Ó Ó
ó ó ó ´ ´ Ô Ô
ô ô ô μ µ µ Õ Õ
õ õ õ
? Ö Ö Ö ö ö ö
· · · × × × ÷ ÷ ÷
? ¸ ¸ Ø Ø Ø ø ø ø
1 ¹ ¹ Ù Ù Ù ù ù ù
o º º Ú Ú Ú ú ú ú
? » » Û Û Û û û û
? ¼ ¼ Ü Ü Ü ü ü ü
? ½ ½ Ý Ý Ý ý ý ý
? ¾ ¾ Þ Þ Þ þ þ þ
? ¿ ¿ ß ß ß ÿ ÿ ÿ
À À À à à à

JavaScript转义符:

转义序列 字符
\b 退格
\f 走纸换页
\n 换行
\r 回车
\t 横向跳格 (Ctrl-I)
\' 单引号
\" 双引号
\\ 反斜杠


编程的时候要注意特殊字符的问题,很多运行时出现的问题都是因为特殊字符的出现而引起的。


注意,由于反斜杠本身用作转义符,因此不能直接在脚本中键入一个反斜杠。如果要产生一个反斜杠,必须一起键入两个反斜杠 (\\)。


参考资料:

http://114.xixik.com/character/

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
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool