如何使用 JavaScript 获取 HTML 中的 lang 属性?

如何使用 JavaScript 获取 HTML 中的 lang属性?

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
72682 次浏览

Just.

document.getElementsByTagName('html')[0].getAttribute('lang');

And with the namespace

document.getElementsByTagName('html')[0].getAttribute('xml:lang');

If both attributes agree on their values (as they should), it's enough to read either of them. I'd suggest using

document.documentElement.lang