HTMLElement: lang 屬性
HTMLElement 介面的 lang 屬性指示元素屬性值和文字內容的基礎語言,形式為 BCP 47 語言標籤。它反映了元素的 lang 屬性;xml:lang 屬性不會影響此屬性。
請注意,如果 lang 屬性未指定,元素本身可能仍會從其父元素繼承語言。但是,此屬性的值不會反映繼承的語言。
值
一個字串。常見的示例包括英語的“en”,日語的“ja”,西班牙語的“es”等。如果未指定,則值為一個空字串。
示例
js
// this snippet compares the base language and
// redirects to another URL based on language
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";
}
規範
| 規範 |
|---|
| HTML # dom-lang |
瀏覽器相容性
載入中…