代码之家  ›  专栏  ›  技术社区  ›  Gordian Yuan

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

  •  110
  • Gordian Yuan  · 技术社区  · 17 年前

    lang HTML中的属性是否使用JavaScript?

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    2 回复  |  直到 11 年前
        1
  •  108
  •   Christoph    17 年前

    如果两个属性的值一致(应该如此),那么读取其中任何一个就足够了。我建议使用

    document.documentElement.lang
    
        2
  •  23
  •   Christophe Eblé    17 年前

    只是。

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

    document.getElementsByTagName('html')[0].getAttribute('xml:lang');
    
        3
  •  1
  •   Konstantin Smolyanin    13 年前