回复内容:
在页面的编码声明与客户端浏览器的编码识别都可靠的情况下(比如声明了 UTF-8,针对的也都是现代浏览器),对于外观明了且不必转义的字符,没有必要用 character reference(包括 character entity reference 与 numeric character reference)。对于特殊的空格以及各种不可见字符等外观不明了的情况,用 character reference 会方便维护代码。当然,有时查找与输入特殊字符就很不方便,那么用 character reference 倒也方便输入,除此以外没什么好处。
另外,如果一定要用 numeric character reference,我建议用以 &#x 开头的十六进制格式,这样和 Unicode scalar value 一致,比较方便。 刚看了一下,知乎是©;百度首页是©;W3C是©;
目前发现唯一的差别就是字符长度不同,还有就是©;在指定不同编码下如gbk或utf-8下都能正确显示,©不能。
补充下,stackoverflow上的一个答案(貌似没有必要一定要用HTML字符实体?):
You don't generally need to use HTML character entities if your editor supports Unicode. Entities can be useful when:
- Your keyboard does not support the character you need to type. For example, many keyboards do not have em-dash or the copyright symbol.
- Your editor does not support Unicode (very common some years ago, but probably not today).
- You want to make it explicit in the source what is happening. For example, the code is clearer than the corresponding white space character.
- You need to escape HTML special characters like <, &, or ".
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群