HTML 元字符集不起作用

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

HTML meta charset not working

html

提问by Alberto Rossi

At the beginning of my page, I have the following code:

在我的页面的开头,我有以下代码:

<HTML>
<head>
<meta charset="utf-8">
<title> 
//other

I used the metabecause I have to put in my website some Japanese characters. Here you can see an example:

我使用 是meta因为我必须在我的网站中放入一些日语字符。在这里你可以看到一个例子:

<tr>
<td><label class="blacktd" onmouseover="apriimg('imgbox', '4');"> Shy Guy Bazaar </label></td>
<td><a href="http://www.youtube.com/watch?v=kpmkZIcD7fc">2'03"007</a></td>
<td>そうめん</td> //look at here
<td><img src="http://mk7vrlist.altervista.org/flags/jp.gif" /></td>
<td>2013/06/30</td>
</tr>

I googled this and I saw that I simply need to put that tag with the charsetattribute. By the way my webpage shows %u305D%u3046%u3081%u3093instead of "そうめん". Do you know why?

我用谷歌搜索了这个,我看到我只需要把这个标签和charset属性放在一起。顺便说一句,我的网页显示%u305D%u3046%u3081%u3093而不是“そうめん”。你知道为什么吗?

回答by Quentin

Because either:

因为要么:

  • You have an HTTP header which specifies a different character encoding (HTTP headers take priority over meta elements) or
  • You haven't saved the document using UTF-8 (you are just telling the browser that you are)
  • 您有一个指定不同字符编码的 HTTP 标头(HTTP 标头优先于元元素)
  • 您尚未使用 UTF-8 保存文档(您只是告诉浏览器您是)

回答by Michael Summers

Is your doctype HTML5

你的文档类型是 HTML5

<!DOCTYPE html>

if not you have to use this for all other doctypes

如果不是,您必须将其用于所有其他文档类型

<meta http-equiv="content-type" content="text/html; charset=utf-8">

回答by Esmu Igors

Thanks to all answerers, but I have had troubles solving it, as I saved the file in two editors (Leafpad and vim) as UTF-8, still getting weird characters in browser. The culprit was, as described here, the byte order mark, which seems not to be set by default in both the editors but has to be set explicitly in vim:

感谢所有回答者,但我在解决它时遇到了麻烦,因为我将文件保存在两个编辑器(Leafpad 和 vim)中为 UTF-8,但在浏览器中仍然出现奇怪的字符。罪魁祸首是,所描述这里,字节顺序标记,这似乎不被默认在这两个编辑设置,但必须要在vim明确设置:

:set bomb

This solved the problem for me finally.

这最终为我解决了问题。