完美WEB

css,xhtml,javascript,DOM,亲和力,web内容可用性教程,希望web变得更完美。

« 水平分隔线标签hr是“表现标签”吗?正确使用address标签 »

为网页内容设置语言

在HTML/XHTML语言中很多标签都有lang(XHTML中推荐lang和xml:lang同时使用)这个属性,它的作用是用来为一个元素的属性值和文本内容设置语言。这个属性的默认值是“未定义”,即没有分配语言。

lang属性的值是一个“语言代码”(language-code),语言代码由一个“主代码”(primary-code)和一个可选的“子代码”(subcode)系列组成,语法如下:

language-code = primary-code ( "-" subcode )*

也就是说“主代码”是必须有的,而“子代码”可以有0或者很多个。比如:zh-CN(中文-大陆),en(英语),fr(法语)en-US(英语-美国)。怎样设置语言代码值和其语法完整指南可以参考 BCP 47,两个字母的“主代码”可以参考[ISO639]规范。 对于中文网页如果你想表明语言是简体中文或繁体中文则推荐使用zh-Hans(表示简体中文)或zh-Hant(表示繁体中文);如果想表示不同地区则可以使用zh-CN(中文-大陆),zh-TW(中文-台湾),zh-HK(中文-香港),zh-MO(中文-澳门)。

语言代码的继承

元素继承语言代码按照如下优先级: 1.元素本身设置的 lang 属性; 2.元素的父元素的lang 属性; 3.HTTP "Content-Language" 头设置(例如:Content-Language: en-cockney); 4.用户代理的默认值或者用户自己的设置;

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<HTML lang="fr">
<HEAD>
<TITLE>Un document multilingue</TITLE>
</HEAD>
<BODY>
...Interpreted as French...
<P lang="es">...Interpreted as Spanish...
<P>...Interpreted as French again...
<P>...French text interrupted by<EM lang="ja">some
         Japanese</EM>French begins here again...
</BODY>
</HTML>

上面这个例子里,文档的主语言是法语("fr")。有一个段落声明为西班牙语("es"),在这个段落之后,文档语言重新变为法语("fr"),然后下面一个段落包含了一个日语语句,最后文档语言变为法语("fr")。

属性值和元素内容的语言不同

有些中文网站有中文和英文两个版本,比如下面这段代码:

 
<p><a lang="en" title="英语版本" href="http://www.flashshe.com/perfect-web/ADMIN/indexEN.html" xml:lang="en">englishi</a></p>

上面这段代码lang="en"表明a元素的title属性值为英文,显然不恰当,可以修改为如下:

<p title="英语版本"><a lang="en" href="http://www.flashshe.com/perfect-web/ADMIN/indexEN.html" xml:lang="en">englishi</a></p>

这样就对了。当然这个例子只不过是举例,可能并不恰当,目的是希望你能明白怎样处理属性值和元素内容的语言不同的情况。

参考资料:

此文禁止转载,但是您可以以超级链接的方式链接到这篇文章。

  • acylovir(引用)
  • acylovir
  • Now I dont have to feel so intimated by science!
  • 2007-5-16 15:03:26
  • ambein(引用)
  • ambein
  • you think my sites too brilliant?
  • 2007-5-16 15:03:31
  • fiorecet(引用)
  • fiorecet
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-16 15:38:33
  • codein(引用)
  • codein
  • you think my sites too brilliant?
  • 2007-5-16 15:56:47
  • maridia(引用)
  • maridia
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-17 16:23:35
  • ciallis(引用)
  • ciallis
  • Now I dont have to feel so intimated by science!
  • 2007-5-17 16:27:03
  • lortab(引用)
  • lortab
  • Very interesting site!
  • 2007-5-21 8:24:43
  • flexaril(引用)
  • flexaril
  • admins whos create this site, thanks guys.
  • 2007-5-23 1:06:11
  • inamin(引用)
  • inamin
  • admins whos create this site, thanks guys.
  • 2007-5-23 1:13:35
  • cadeine(引用)
  • cadeine
  • Now I dont have to feel so intimated by science!
  • 2007-5-23 1:22:06
  • fiorecet(引用)
  • fiorecet
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-23 1:22:24
  • ulltram(引用)
  • ulltram
  • Now I dont have to feel so intimated by science!
  • 2007-5-23 1:23:20
  • miridia(引用)
  • miridia
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-27 3:56:31
  • wellbutren(引用)
  • wellbutren
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-28 2:37:27
  • cheap soma(引用)
  • cheap soma
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-28 2:38:20
  • zonaflex(引用)
  • zonaflex
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-28 2:39:11
  • zybane(引用)
  • zybane
  • you think my sites too brilliant?
  • 2007-5-28 2:56:18
  • vallum(引用)
  • vallum
  • Very interesting site!
  • 2007-5-28 3:00:09
  • zanax(引用)
  • zanax
  • Very interesting site!
  • 2007-5-28 3:00:26
  • prozak(引用)
  • prozak
  • admins whos create this site, thanks guys.
  • 2007-5-28 5:14:24
  • zolof(引用)
  • zolof
  • admins whos create this site, thanks guys.
  • 2007-5-28 5:18:19
  • lipitorr(引用)
  • lipitorr
  • Now I dont have to feel so intimated by science!
  • 2007-5-30 9:51:27
  • ellegra(引用)
  • ellegra
  • you think my sites too brilliant?
  • 2007-5-30 9:51:37
  • zyrtek(引用)
  • zyrtek
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-5-30 9:51:42
  • codein(引用)
  • codein
  • Very interesting site!
  • 2007-6-1 14:30:54
  • adderal(引用)
  • adderal
  • you think my sites too brilliant?
  • 2007-6-1 22:48:21
  • amben(引用)
  • amben
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-6-1 22:51:30
  • fearicet(引用)
  • fearicet
  • Hello, Glad to find your site. Just one more time I want to thank the
  • 2007-6-2 4:30:34
  • vallum(引用)
  • vallum
  • admins whos create this site, thanks guys.
  • 2007-6-2 5:19:09
  • sanax(引用)
  • sanax
  • you think my sites too brilliant?
  • 2007-6-2 13:15:04
  • merridia(引用)
  • merridia
  • admins whos create this site, thanks guys.
  • 2007-6-4 1:06:48
  • fearicet(引用)
  • fearicet
  • admins whos create this site, thanks guys.
  • 2007-6-8 5:39:46
  • xenikal(引用)
  • xenikal
  • Hello man, your site best, ciao!
  • 2007-6-8 5:42:05
  • lavitra(引用)
  • lavitra
  • you think my sites too brilliant?
  • 2007-6-8 5:45:49
  • vigra(引用)
  • vigra
  • admins whos create this site, thanks guys.
  • 2007-6-8 5:46:56
  • cialiss(引用)
  • cialiss
  • admins whos create this site, thanks guys.
  • 2007-6-8 5:53:05
  • adderal(引用)
  • adderal
  • admins whos create this site, thanks guys.
  • 2007-6-8 14:11:50
  • ambien cr(引用)
  • ambien cr
  • Now I dont have to feel so intimated by science!
  • 2007-6-8 14:59:29
  • lortab(引用)
  • lortab
  • Now I dont have to feel so intimated by science!
  • 2007-6-15 8:40:18
  • merridia(引用)
  • merridia
  • admins whos create this site, thanks guys.
  • 2007-6-15 8:44:19
  • flexerile(引用)
  • flexerile
  • Now I dont have to feel so intimated by science!
  • 2007-6-15 9:00:12
  • paxill(引用)
  • paxill
  • you think my sites too brilliant?
  • 2007-6-15 9:00:21
  • ultam(引用)
  • ultam
  • admins whos create this site, thanks guys.
  • 2007-6-15 9:03:31
  • ulltram(引用)
  • ulltram
  • you think my sites too brilliant?
  • 2007-6-15 21:34:45
  • somma(引用)
  • somma
  • Now I dont have to feel so intimated by science!
  • 2007-6-19 3:14:53
  • vallum(引用)
  • vallum
  • Hello man, your site best, ciao!
  • 2007-6-21 21:43:04
  • lepitor(引用)
  • lepitor
  • admins whos create this site, thanks guys.
  • 2007-6-21 21:45:36
  • zybane(引用)
  • zybane
  • you think my sites too brilliant?
  • 2007-6-21 21:54:57
  • lavetra(引用)
  • lavetra
  • Hello man, your site best, ciao!
  • 2007-6-21 23:02:52
  • cealis(引用)
  • cealis
  • admins whos create this site, thanks guys.
  • 2007-6-22 1:06:50
  • zybane(引用)
  • zybane
  • you think my sites too brilliant?
  • 2007-6-22 12:09:51
  • ativane(引用)
  • ativane
  • you think my sites too brilliant?
  • 2007-6-22 12:17:45
  • xanex(引用)
  • xanex
  • admins whos create this site, thanks guys.
  • 2007-6-22 12:18:03
  • xannax(引用)
  • xannax
  • you think my sites too brilliant?
  • 2007-6-23 12:39:47
  • prilocek(引用)
  • prilocek
  • you think my sites too brilliant?
  • 2007-6-23 12:40:42
  • voltrax(引用)
  • voltrax
  • admins whos create this site, thanks guys.
  • 2007-6-23 12:41:04
  • exema(引用)
  • exema
  • you think my sites too brilliant?
  • 2007-6-23 12:57:53
  • zokor(引用)
  • zokor
  • you think my sites too brilliant?
  • 2007-6-24 3:43:48
  • amben(引用)
  • amben
  • you think my sites too brilliant?
  • 2007-6-25 5:00:50

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。



日历

网站目录

最新评论

最近发表

Powered By Z-Blog 1.6 Beta Build 60420

Copyright flashshe.com All Rights Reserved.