console.log("lang = " + document.documentElement.lang);
<html>
<head>
<meta http-equiv="content-language" content="es">
</head>
<body></body>
<html>
为什么?
According to specification ,如果该节点或该节点的任何祖先(包括根元素)都没有设置任一属性,但存在 pragma-set 默认语言设置,则该语言就是该节点的语言。
最佳答案
This feature is non-conforming. Authors are encouraged to use the lang attribute instead.
The
Content-Language
value for anhttp-equiv
attribute on ameta
element should no longer be used.
如What is the HTML5 alternative to the obsolete meta http-equiv=content-language.建议,使用 lang=
代替可以:
console.log("lang = " + document.documentElement.lang);
<html lang="es">
如果您的目标是设置语言,这是一个更好的方法。
关于javascript - http-equiv ="content-language"不起作用(element.lang = ""),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39423840/