HTMLElement:lang 屬性
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
HTMLElement 介面的 lang 屬性以 BCP 47 語言標籤的形式,表示元素屬性值與文字內容的基礎語言。它反映了元素的 lang 屬性;xml:lang 屬性不影響此屬性。
注意,如果未指定 lang 屬性,元素本身仍可能從其父元素繼承語言。然而,該繼承的語言不會反映在此屬性的值中。
值
一個字串。常見的範例包括代表英文的「en」、代表日文的「ja」、代表西班牙文的「es」等等。如果未指定,則值為空字串。
範例
js
// 此片段比較基礎語言,並
// 根據語言重新導向至另一個 URL
if (document.documentElement.lang === "en") {
window.location.href = "Some_document.html.en";
} else if (document.documentElement.lang === "ru") {
window.location.href = "Some_document.html.ru";
}
規範
| Specification |
|---|
| HTML> # dom-lang> |