Html 什么是 <meta charset="utf-8">?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29869743/
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-29 03:54:25  来源:igfitidea点击:

what is <meta charset="utf-8">?

htmlcssutf-8

提问by Fedora

I just started learning HTML (no coding background) and don't know what this means. I generally write it when I start the code after but have no idea what it means. I also do not know what doctype means. What will happen if I don't use it?

我刚开始学习 HTML(没有编码背景),不知道这意味着什么。我通常在之后开始编写代码时编写它,但不知道它的含义。我也不知道 doctype 是什么意思。如果我不使用它会怎样?

回答by Peter Morris

The characters you are reading on your screen now each have a numerical value. In the ASCII format, for example, the letter 'A' is 65, 'B' is 66, and so on. If you look at a table of charactersavailable in ASCII you will see that it isn't much use for someone who wishes to write something in Mandarin, Arabic, or Japanese. For characters / words from those languages to be displayed we needed another system of encoding them to and from numbers stored in computer memory.

您在屏幕上阅读的字符现在每个都有一个数值。例如,在 ASCII 格式中,字母“A”为 65,“B”为 66,依此类推。如果您查看ASCII 可用字符表,您会发现它对于希望用普通话、阿拉伯语或日语写东西的人来说没有多大用处。为了显示来自这些语言的字符/单词,我们需要另一个系统将它们与存储在计算机内存中的数字进行编码。

UTF-8 is just one of the encoding methods that were invented to implement this requirement. It lets you write text in all kinds of languages, so French accents will appear perfectly fine, as will text like this

UTF-8 只是为实现此要求而发明的编码方法之一。它可以让你用各种语言写文本,所以法语口音会显得非常好,像这样的文本

Бзиа збаша (Bzia zba?a), Фэсапщы, ?'kemi, ???, and even right-to-left writing such as this ?????? ?????

Бзиа збаша (Bzia zba?a), Фэсапщы, ?'kemi, ???, 甚至像这样的从右到左书写?????? ?????

If you copy and paste the above text into notepad and then try to save the file as ANSI (another format) you will receive a warning that saving in this format will lose some of the formatting. Accept it, then re-load the text file and you'll see something like this

如果您将上述文本复制并粘贴到记事本中,然后尝试将文件另存为 ANSI(另一种格式),您将收到一条警告,指出以这种格式保存将丢失某些格式。接受它,然后重新加载文本文件,你会看到这样的

???? ????? (Bzia zbasa), ???????, ?'kemi, ???, and even right-to-left writing such as this ?????? ?????

???????? (Bzia zbasa), ???????, ?'kemi, ???, 甚至像这样的从右到左书写?????? ?????

回答by AndrewL64

That meta tag basically specifies which character seta website is written with.

该元标记基本上指定了网站是用哪个字符集编写的。

Here is a definition of UTF-8:

下面是 UTF-8 的定义:

UTF-8 (U from Universal Character Set + Transformation Format—8-bit) is a character encoding capable of encoding all possible characters (called code points) in Unicode. The encoding is variable-length and uses 8-bit code units.

UTF-8(来自通用字符集的 U + 转换格式—8 位)是一种字符编码,能够以 Unicode 编码所有可能的字符(称为代码点)。编码是可变长度的并使用 8 位代码单元。