我可以使用元标记在一个 HTML 页面上声明两个不同的字符集吗?
可以使用元标记在页面上指定两个不同的字符集,例如:
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
我尝试添加它们,但不起作用:P
谢谢
Is possible to specify two different character sets on a page using meta tags, like:
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
I tried to add both of them and doesn't work :P
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这是不可能的。添加两个不同的字符集声明有什么意义?您应该仅添加一项与您的内容相匹配的声明。
No, it's not possible. What would be the point of adding two different charset declarations? You should add only one declaration that matches your content.
在本文中,“字符集”更适合称为“文本编码”。计算机将文本存储为数字。对于给定的存储文本,编码定义了哪些字符由哪些数字表示。
因为 HTML 是文本,为了显示它,浏览器需要知道文本采用什么编码。因此,您不能在一个 HTML 页面中使用两种编码,因为一个 HTML 页面就是一大堆文本,并且声明的编码适用于所有这一切。
正如 @TomasMarkauskas 所解释的,UTF-8 编码可以表示 ISO-8859-1 可以表示的所有字符(以及一些字符)比 ISO-8859-1 不能)。因此,您需要对 HTML 页面使用 UTF-8。
A "character set" is better referred to in this context as a "text encoding". Text is stored by computers as numbers. For a given piece of stored text, the encoding is the thing that defines which characters are represented by which numbers.
Because HTML is text, in order to display it, the browser needs to know what encoding the text is in. You therefore can't use two encodings in one HTML page, because one HTML page is one lump of text, and the declared encoding applies to all of it.
As @TomasMarkauskas has explained, the UTF-8 encoding can represent all characters that ISO-8859-1 can (and some characters than ISO-8859-1 can't). So you'll want to use UTF-8 for your HTML pages.