当我在 Visual Studio 2017 中创建一个新的 Html 文件时,这个:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
总是出现在
<head>
.没有它,程序运行得很好。那么,有人可以告诉我它有什么作用吗?
最佳答案
根据 HTML Dog :
The charset attribute can be used as a shorthand method to define an HTML document's character set, which is always a good thing to do.
<meta charset="utf-8">
is the same as<meta http-equiv="content-type" content="text/html; charset=utf-8">
.
所以它基本上用于定义 HTML 文档的字符集。
Visual Studio 2017 添加这两个元标记的原因可能是因为这样您的 HTML 将最大程度地与旧浏览器兼容。
<meta http-equiv="content-type" content="text/html; charset=utf-8">
是定义字符集的旧方法。<meta charset="utf-8">
是做同样事情的新的和更短的方法。
关于html - 什么是 <meta http-equiv ="Content-Type"content ="text/html; charset=utf-8"/>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51006665/