Home Web Front-end HTML Tutorial HTML escape character table_html/css_WEB-ITnose

HTML escape character table_html/css_WEB-ITnose

Jun 24, 2016 am 11:45 AM

为什么要用转义字符串?

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

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


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


转义字符串的组成

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

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

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

第三部分是一个分号。


比如,要显示小于号(<),就可以写 < 或者 < 。

用实体(Entity)名字的好处是比较好理解,一看lt,大概就猜出是less than的意思,但是其劣势在于并不是所有的浏览器都支持最新的Entity名字。而实体(Entity)编号,各种浏览器都能处理。

提示:实体名称(Entity)是区分大小写的。

备注:同一个符号,可以用“实体名称”和“实体编号”两种方式引用,“实体名称”的优势在于便于记忆,但不能保证所有的浏览器都能顺利识别它,而“实体编号”则没有这种担忧,但它实在不方便记忆。


如何显示空格?

通常情况下,HTML会自动截去多余的空格。不管你加多少空格,都被看做一个空格。比如你在两个字之间加了10个空格,HTML会截去9个空格,只保留一个。为了在网页中增加空格,你可以使用 表示空格。


HTML特殊转义字符列表

最常用的字符实体:

显示 说明 实体名称 实体编号

半方大的空白
全方大的空白
不断行的空白格  
< 小于 < <
>

大于 > >
& &符号 & &
" 双引号 " "
© 版权 © ©
® 已注册商标 ® ®
? 商标(美国) ?
× 乘号 × ×
÷ 除号 ÷ ÷
字符 十进制 转义字符
" " "
& & &
< < <
> > >
不断开空格(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 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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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 &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

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 &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

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 &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles