什么时候应该使用HTML实体? [英] When should one use HTML entities?
本文介绍了什么时候应该使用HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这已经使我困惑了一段时间.随着UTF-8作为Web开发中的实际标准的出现,我不确定在哪种情况下应该使用HTML实体,对于哪种情况我应该仅使用UTF-8字符.例如,
This has been confusing me for some time. With the advent of UTF-8 as the de-facto standard in web development I'm not sure in which situations I'm supposed to use the HTML entities and for which ones should I just use the UTF-8 character. For example,
- 破折号(–,
&emdash;
) - &符(& ;,
&
) - 3/4分数(¾,
¾
)
- em dash (–,
&emdash;
) - ampersand (&,
&
) - 3/4 fraction (¾,
¾
)
请阐明此问题.将不胜感激.
Please do shed light on this issue. It will be appreciated.
推荐答案
如果您的编辑器支持Unicode,则通常不需要使用HTML字符实体.在以下情况下,实体会很有用:
You don't generally need to use HTML character entities if your editor supports Unicode. Entities can be useful when:
- 您的键盘不支持您需要输入的字符.例如,许多键盘没有破折号或版权符号.
- 您的编辑器不支持Unicode(几年前很常见,但今天可能不常见).
- 您想在源代码中明确说明正在发生的事情.例如,
代码比相应的空白字符更清晰. - 您需要转义HTML特殊字符,例如
<
,&
或"
.
- 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"
.
这篇关于什么时候应该使用HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文