何时应该使用HTML实体 [英] When Should One Use HTML Entities

查看:86
本文介绍了何时应该使用HTML实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一直困扰着我一段时间。随着UTF-8作为Web开发事实上的标准的出现,我不确定我应该在哪些情况下使用html实体,哪些情况下我应该只使用UTF-8字符。



示例:em短划线,&符号等。



请在这个问题上说明问题。如果您的编辑器支持Unicode,您通常不需要使用HTML字符实体。

在以下情况下,实体可能很有用:


  • 您的键盘不支持您需要输入的字符。例如,许多键盘没有em-dash或版权符号。

  • 您的编辑器不支持Unicode(几年前很常见,但可能不是今天)。

  • 您想在源代码中明确说明正在发生的事情。例如,& nbsp; 代码比相应的空白字符更清晰。

  • 您需要转义HTML特殊字符< & li>

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.

Examples: em dash, ampersand, etc.

Please do shed light on this issue. It will be appreciated.

解决方案

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 &nbsp; code is clearer than the corresponding white space character.
  • You need to escape HTML special characters like <, &, or ".

这篇关于何时应该使用HTML实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆