Html html中的转义标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/692123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:31:17  来源:igfitidea点击:

Escape tags in html

htmltagsescaping

提问by

What are escape tags in html?

html中的转义标签是什么?

Are they &#34;&#60;&#62;to represent "<>?
And how do these work?
Is that hex, or what is it?
How is it made, and why aren't they just the characters themselves?

他们&#34;&#60;&#62;要代表"<>吗?
这些是如何工作的?
那是十六进制,还是什么?
它是如何制作的,为什么它们不只是角色本身?

回答by jthompson

Here are some common entities. You do not need to use the full code - there are common aliases for frequently used entities. For example, you can use < and > to indicate less than and greater than symbols. & is ampersand, etc.

下面是一些常见的实体。您不需要使用完整代码 - 常用实体有通用别名。例如,您可以使用 < 和 > 来表示小于和大于符号。& 是&符号等。

EDIT: That should be - &lt; &gt; and &amp;

编辑:那应该是- &lt; &gt; and &amp;

EDIT: Another common character is &nbspwhich is often used to represent tabs in <code>segments

编辑:另一个常见字符&nbsp通常用于表示<code>段中的制表符

回答by Maiku Mori

How do these work?

这些是如何工作的?

Anything &#num;is replaced with character from ASCII table, matching that num.

任何东西&#num;都被 ASCII 表中的字符替换,匹配那个num.

Is that hex, or what is it?

那是十六进制,还是什么?

It's not hex, the number represents characters number in decimal in ASCII table. Check out ASCII table. Check Dec and HTML columns.

它不是十六进制,数字代表ASCII表中十进制的字符数。查看ASCII 表。检查 Dec 和 HTML 列。

Why aren't they just the characters themselves?

为什么他们不只是角色本身?

Look at this example:

看这个例子:

<div>Hey you can use </div> to end div tag!</div>

It would mess up the interpreter. It's a bad example, but you got the idea.

它会搞乱口译员。这是一个不好的例子,但你明白了。

Why you can't use escape characters like in programming languages?

为什么不能像在编程语言中那样使用转义字符?

I don't have exact answer to that. But html same as xml is a markup language and not programming language and answer probably lies within history of how markup languages become what they are now.

对此我没有确切的答案。但是 html 与 xml 一样是一种标记语言而不是编程语言,答案可能就在标记语言如何成为现在的样子的历史中。

回答by Maiku Mori

No, it's not hex, it's decimal. Hex equivalent is &#x3c; But one usually uses &lt; (less-than) for < and &gt; for > instead.

不,它不是十六进制,它是十进制。十六进制等效是 < 但是通常使用 < (小于) < 和 > 代替 >。

回答by John Cris Ma?abo

Here is the complete reference of html entities:

这是 html 实体的完整参考:

Complete HTML Entities

完整的 HTML 实体

It is use for correct character formatting

它用于正确的字符格式

HTML has a set of special characters which browsers recognize as part of the HTML language itself. For example, browsers know that when they encounter a < character in the HTML code, they are to interpret it as a beginning of a tag. > is one of an example of reserved character. Therefore use html character to avoid any problem and for correct practice also

HTML 有一组特殊字符,浏览器将其识别为 HTML 语言本身的一部分。例如,浏览器知道当它们在 HTML 代码中遇到 < 字符时,它们会将其解释为标签的开头。> 是保留字符的示例之一。因此,使用 html 字符来避免任何问题并进行正确的练习

回答by Travis Jensen

Those escapes are decimal ascii escapes. You can see the values here. Take a look at the HTML column.

这些转义是十进制的 ascii 转义。您可以在此处查看这些值。看一看 HTML 列。