1

我对 HTML5 的理解是

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

在文档标题中,唯一需要转换为实体的字符是 > < & ' 和 "。

  1. 这个对吗?
  2. 在一些基本的测试中,在 Chrome 中,我发现我可以坚持 - 例如 - 文字 < 并摆脱它。这只是不好的做法还是实体规则有更多细微差别?
4

1 回答 1

2

The chars < > & are special. They are required to be escaped, so the parser isn't confused and you are able to display them. That's independent of the charset.

Older charsets are not able to display things like ä ö ü ß, so you have to escape them. In UTF-8 you don't need to use the entities, because the encoding supports them native and they don't confuse with XML syntax.

' " are also special but only in attributes, where you want to ensure that a double quotation can be inside of a double quote notated attribute (the like with a single quote char inside of single quotes attribute).
It's like other languages where you can exchange to notation, for example '"' and "'". Now if you are building the value from a database, you don't have to swap quotes around, you can simply escape them using entities.

于 2013-04-15T13:20:06.547 回答