长: 长: 长: 长:

<meta charset =“ utf-8”>与<meta http-equiv =“ Content-Type”>

html HTML

猴子小小Mandy

2020-03-13

为了为HTML5 Doctype定义字符集,我应该使用哪种表示法?

  1. 短:

    <meta charset="utf-8" /> 
    
  2. 长:

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

第1495篇《<meta charset =“ utf-8”>与<meta http-equiv =“ Content-Type”>》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

6个回答
神乐Jim 2020.03.13

<meta charset="utf-8"> 是随HTML5一起引入的。

如文档中所述,两者均有效。但是,<meta charset="utf-8">仅适用于HTML5(更易于键入/记住)。

不久的将来,旧样式必定会过时我会坚持新的<meta charset="utf-8">

只有一种方法,但是向上。以技术为例,那是淘汰旧的(真的,真的很快)

文档: HTML元字符集属性-W3Schools

宝儿LEY理查德 2020.03.13

两种形式的meta charset声明都是等效的,并且在浏览器之间应相同。但是,在将Web文件的字符集声明为UTF-8时,需要记住一些事项:

  1. 保存文件(S)以UTF-8编码,而不字节顺序标记(BOM)。
  2. Declare the encoding in your HTML files using meta charset (like above).
  3. Your web server must serve your files, declaring the UTF-8 encoding in the Content-Type HTTP header.

Apache servers are configured to serve files in ISO-8859-1 by default, so you need to add the following line to your .htaccess file:

AddDefaultCharset UTF-8

This will configure Apache to serve your files declaring UTF-8 encoding in the Content-Type response header, but your files must be saved in UTF-8 (without BOM) to begin with.

Notepad cannot save your files in UTF-8 without the BOM. A free editor that can is Notepad++. On the program menu bar, select "Encoding > Encode in UTF-8 without BOM". You can also open files and re-save them in UTF-8 using "Encoding > Convert to UTF-8 without BOM".

More on the Byte Order Mark (BOM) at Wikipedia.

小哥卡卡西 2020.03.13

要将签名嵌入到电子邮件中,我将使用长版本:

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

原因是使用html5的电子邮件阅读器并不多,因此始终最好使用旧的html样式。实际上,使用表比使用divs + css更好。

.... 2020.03.13

使用<meta charset="utf-8" />HTML5时用于Web浏览器。

使用<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />使用HTML4和XHTML时,或过时的DOM解析器,像DOMDocument在PHP 5.3

乐米亚 2020.03.13

有一些基于Mozilla Foundationsitepoint的新闻

请勿使用该值(http-equiv=content-type),因为它已过时。优先使用charset< meta>元素属性在此处输入图片说明

小小西门 2020.03.13

在HTML5中,它们是等效的。使用较短的一个,更容易记住和键入。浏览器支持很好,因为它是为向后兼容而设计的。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android