may梅本屋 - 歪酷博客 Ycool Blog 订阅 RSS

歪酷博客
MAY梅 @ 2017-11-24 11:14

1.may梅博客图片预览方法

详细请点击下方“阅读全文”


 
MAY梅 @ 2008-08-06 14:13

HTML 5 中的新元素

结构和语义

developerWorks
文档选项
>
将此页作为电子邮件发送

将此页作为电子邮件发送


级别: 初级

Elliotte Rusty Harold (elharo@metalab.unc.edu), 副教授, Polytechnic University

2007 年 8 月 27 日

新千年以来,超文本标记语言(HTML)5 第一次向 HTML 中引入新的元素。新的结构元素包括 asidefiguresection。新的内联元素包括 timemeterprogress。新的内嵌元素有 videoaudio。新的交互元素有 detailsdatagridcommand

超文本标记语言(HTML)的开发到 1999 年 HTML 4 就停止了。万维网联盟(W3C)把重点转向将 HTML 的底层语法从标准通用标记语言(SGML)改为可扩展标记语言(XML),以及可缩放向量图型(SVG)、XForms 和 MathML 这些全新的标记语言。浏览器厂商则把精力放到选项卡和富站点摘要(RSS)阅读器这类浏览器特性上。Web 设计人员开始学习使用异步 JavaScript + XML(Ajax),在现有的框架下通过层叠样式表(CSS)和 JavaScript™ 语言建立自己的应用程序。但是在接下来的八年中,HTML 本身没有任何变化。

最近,它又复活了。三家重要的浏览器厂商 — Apple、Opera 和 Mozilla Foundation — 成立了 Web Hypertext Application Technology Working Group(WhatWG)来开发传统 HTML 的新版本。最近,W3C 也注意到了这些活动,也启动了自己的新一代 HTML 项目,双方的成员有很多是相同的。这两个项目最终很可能合并。虽然很多细节还在争论之中,但下一版本 HTML 的大体轮廓已经清楚了。

Web 开发人员从 1999 年就一直期待 HTML 的新版本(通常称为 HTML 5,但是也称为 Web Applications 1.0),现在它终于发布了。它保持了 HTML 原来的特色:没有名称空间或模式。元素不必结束。浏览器会宽容地对待错误。p 仍然是 ptable 仍然是 table

如果在 1999 年将一位 Web 开发人员冷冻起来,现在再解冻,那么他会遇到一些新的让人迷惑的元素。是的,他熟悉的元素(比如 div)仍然保留了;但是,HTML 现在还包含 sectionheaderfooternav 等新元素。emcodestrong 仍然存在,但是增加了 metertimemimgembed 仍然可用,但是还增加了 videoaudio。但是,他仔细观察一下就会发现,这些元素实际上没什么区别。其中许多元素可能在 1999 年是开发人员需要而没有得到的。通过与他已经掌握的元素进行简单的类比,这些新元素都很容易理解。实际上,与 Ajax 或 CSS 相比,它们非常容易掌握。

最后,当他打开 300MHz 的笔记本(运行的是 Windows 98,也是在 1999 年冷冻起来的)时,他可能对 Netscape 4 和 Windows® Internet Explorer® 5 中显示的新页面效果很吃惊。当然,这些老式浏览器不认识新元素,会完全忽略它们,但是页面仍然会显示,内容仍然是完整的。

这并不是什么虚构的故事。HTML 5 的设计原则就是在不支持它的浏览器中能够平稳地退化。原因很简单:我们都是这样的 “原始人”。浏览器现在有选项卡、CSS 和 XmlHttpRequest,但是它们的 HTML 显示引擎仍然停留在 1999 年的水平。除了用户量大大增加之外,Web 其实在本质上没什么进步。HTML 5 考虑到了这一点。它目前为 Web 开发人员一些真正的好处,随着浏览器的缓慢升级,页面浏览者会逐渐享受到这些好处。我们来看看 HTML 5 提供了什么。

结构

由于缺少结构,即使是形式良好的 HTML 页面也比较难以处理。必须分析标题的级别,才能看出各个部分的划分方式。边栏、页脚、页眉、导航条、主内容区和各篇文章都由通用的 div 元素来表示。HTML 5 添加了一些新元素,专门用来标识这些常见的结构:

  • section:这可以是书中的一章或一节,实际上可以是在 HTML 4 中有自己的标题的任何东西
  • header:页面上显示的页眉;与 head 元素不一样
  • footer:页脚;可以显示电子邮件中的签名
  • nav:指向其他页面的一组链接
  • article:blog、杂志、文章汇编等中的一篇文章

我们来考虑一个典型的 blog 主页,它的顶部有页眉,底部有页脚,还有几篇文章、一个导航区和一个边栏,见清单 1。


清单 1. 典型的 blog 页面
                
<html>
  <head>
    <title>Mokka mit Schlag </title>
 </head>
<body>
<div id="page">
  <div id="header">
    <h1><a href="http://www.elharo.com/blog">Mokka mit Schlag</a></h1>
  </div>
  <div id="container">
    <div id="center" class="column">               
      <div class="post" id="post-1000572">
        <h2><a href=
      "/blog/birding/2007/04/23/spring-comes-and-goes-in-sussex-county/">
      Spring Comes (and Goes) in Sussex County</a></h2>
        
        <div class="entry">
          <p>Yesterday I joined the Brooklyn Bird Club for our
          annual trip to Western New Jersey, specifically Hyper
          Humus, a relatively recently discovered hot spot. It
          started out as a nice winter morning when we arrived
          at the site at 7:30 A.M., progressed to Spring around
          10:00 A.M., and reached early summer by 10:15. </p>
        </div>
      </div>


      <div class="post" id="post-1000571">
        <h2><a href=
          "/blog/birding/2007/04/23/but-does-it-count-for-your-life-list/">
           But does it count for your life list?</a></h2>
        
        <div class="entry">
          <p>Seems you can now go <a
          href="http://www.wired.com/science/discoveries/news/
          2007/04/cone_sf">bird watching via the Internet</a>. I
          haven't been able to test it out yet (20 user
          limit apparently) but this is certainly cool.
          Personally, I can't imagine it replacing
          actually being out in the field by any small amount.
          On the other hand, I've always found it quite
          sad to meet senior birders who are no longer able to
          hold binoculars steady or get to the park. I can
          imagine this might be of some interest to them. At
          least one elderly birder did a big year on TV, after
          he could no longer get out so much. This certainly
          tops that.</p>
        </div>
      </div>

      </div>
    
    <div class="navigation">
      <div class="alignleft">
         <a href="/blog/page/2/">&laquo; Previous Entries</a>
       </div>
      <div class="alignright"></div>
    </div>
  </div>

  <div id="right" class="column">
    <ul id="sidebar">
      <li><h2>Info</h2>
      <ul>
        <li><a href="/blog/comment-policy/">Comment Policy</a></li>
        <li><a href="/blog/todo-list/">Todo List</a></li>
      </ul></li>
      <li><h2>Archives</h2>
        <ul>
          <li><a href='/blog/2007/04/'>April 2007</a></li>
          <li><a href='/blog/2007/03/'>March 2007</a></li>
          <li><a href='/blog/2007/02/'>February 2007</a></li>
          <li><a href='/blog/2007/01/'>January 2007</a></li>
        </ul>
      </li>
    </ul>
  </div>
  <div id="footer">
    <p>Copyright 2007 Elliotte Rusty Harold</p>
  </div>
</div>
  
</body>
</html>

即使有正确的缩进,这些嵌套的 div 仍然让人觉得非常混乱。在 HTML 5 中,可以将这些元素替换为语义性的元素,见清单 2。


清单 2. 用 HTML 5 编写的典型 blog 页面
                
<html>
 <head>
    <title>Mokka mit Schlag </title>
 </head>
<body>
  <header>
    <h1><a href="http://www.elharo.com/blog">Mokka mit Schlag</a></h1>
  </header>
  <section>               
      <article>
        <h2><a href=
        "/blog/birding/2007/04/23/spring-comes-and-goes-in-sussex-county/">
         Spring Comes (and Goes) in Sussex County</a></h2>
        
        <p>Yesterday I joined the Brooklyn Bird Club for our
        annual trip to Western New Jersey, specifically Hyper
        Humus, a relatively recently discovered hot spot. It
        started out as a nice winter morning when we arrived at
        the site at 7:30 A.M., progressed to Spring around 10:00
        A.M., and reached early summer by 10:15. </p>
      </article>


      <article>
        <h2><a href=
          "/blog/birding/2007/04/23/but-does-it-count-for-your-life-list/">
          But does it count for your life list?</a></h2>
        
          <p>Seems you can now go <a
          href="http://www.wired.com/science/discoveries/news/
          2007/04/cone_sf">bird watching via the Internet</a>. I
          haven't been able to test it out yet (20 user
          limit apparently) but this is certainly cool.
          Personally, I can't imagine it replacing
          actually being out in the field by any small amount.
          On the other hand, I've always found it quite
          sad to meet senior birders who are no longer able to
          hold binoculars steady or get to the park. I can
          imagine this might be of some interest to them. At
          least one elderly birder did a big year on TV, after
          he could no longer get out so much. This certainly
          tops that.</p>
      </article>    
    <nav>
      <a href="/blog/page/2/">&laquo; Previous Entries</a>
    </nav>
  </section>

  <nav>
    <ul>
      <li><h2>Info</h2>
      <ul>
        <li><a href="/blog/comment-policy/">Comment Policy</a></li>
        <li><a href="/blog/todo-list/">Todo List</a></li>
      </ul></li>
      <li><h2>Archives</h2>
        <ul>
          <li><a href='/blog/2007/04/'>April 2007</a></li>
          <li><a href='/blog/2007/03/'>March 2007</a></li>
          <li><a href='/blog/2007/02/'>February 2007</a></li>
          <li><a href='/blog/2007/01/'>January 2007</a></li>
        </ul>
      </li>
    </ul>
  </nav>
  <footer>
    <p>Copyright 2007 Elliotte Rusty Harold</p>
  </footer>
  
</body>
</html>

现在不再需要 div 了。不再需要自己设置 class 属性,从标准的元素名就可以推断出各个部分的意义。这对于音频浏览器、手机浏览器和其他非标准浏览器尤其重要。





回页首


语义性的块元素

除了结构性元素之外,HTML 5 还增加了一些纯语义性的块级元素:

  • aside
  • figure
  • dialog

我在文章和书中一直使用前两个元素。第三个元素我不经常用,它主要用于书面文本。

aside

aside 元素代表说明、提示、边栏、引用、附加注释等,也就是叙述主线之外的内容。例如,在 developerWorks 文章中,常常会看到用表格形式编写的边栏,见清单 3。


清单 3. 用 HTML 4 编写的 developerWorks 边栏
                
<table align="right" border="0" cellpadding="0" cellspacing="0" width="40%">
<tbody><tr><td width="10">
<img alt="" src="//www.ibm.com/i/c.gif" height="1" width="10"></td>
<td>
<table border="1" cellpadding="5" cellspacing="0" width="100%">
<tbody><tr><td bgcolor="#eeeeee">
<p><a name="xf-value"><span class="smalltitle">.xf-value</span></a></p>
<p>
The <code type="inline">.xf-value</code> selector used here styles the input
field value but not its label. This is actually inconsistent
with the current CSS3 draft. The example really should use the
<code type="inline">::value</code> pseudo-class instead like so:
</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr><td class="code-outline">
<pre class="displaycode">input::value { width: 20em; }
#ccnumber::value { width: 18em }
#zip::value { width: 12em }
#state::value { width: 3em  }</pre>
</td></tr></tbody></table><br>

<p>
However, Firefox doesn't yet support this syntax. 
</p>
</td></tr></table>

在 HTML 5 中,可以按照更有意义的方式编写这个边栏,见清单 4。


清单 4. 用 HTML 5 编写的 developerWorks 边栏
                
<aside>
<h3>.xf-value</h3>
<p>
The <code type="inline">.xf-value</code> selector used here styles the input
field value but not its label. This is actually inconsistent
with the current CSS3 draft. The example really should use the
<code type="inline">::value</code> pseudo-class instead like so:
</p>
  
<pre class="displaycode">input::value { width: 20em; }
#ccnumber::value { width: 18em }
#zip::value { width: 12em }
#state::value { width: 3em  }</pre>

<p>
However, Firefox doesn't yet support this syntax. 
</p>
</aside>

浏览器可以决定把这个边栏放在哪里(可能需要用一点儿 CSS 代码)。

figure

figure 元素代表一个块级图像,还可以包含说明。例如,在许多 developerWorks 文章中,可以看到清单 5 这样的标记;其结果见图 1。


清单 5. 用 HTML 4 编写的 developerWorks 图
                
<a name="fig2"><b>Figure 2. Install Mozilla XForms dialog</b></a><br />
<img alt="A Web site is requesting permission to install the following item: 
   Mozilla XForms 0.7 Unsigned" 
  src="installdialog.jpg" border="0" height="317" hspace="5" vspace="5" width="331" />
<br />


图 1. Install Mozilla XForms dialog
A Web site is requesting permission to install the following item: Mozilla XForms 0.7 Unsigned

在 HTML 5 中,可以按照更有语义性的方式编写这个图,见清单 6。


清单 6. 用 HTML 5 编写的 developerWorks 图
                
<figure id="fig2">
  <legend>Figure 2. Install Mozilla XForms dialog</legend>
  <img alt="A Web site is requesting permission to install the following item: 
    Mozilla XForms 0.7 Unsigned" 
    src="installdialog.jpg" border="0" height="317" hspace="5" vspace="5" width="331" />
</figure>

最重要的是,浏览器(尤其是屏幕阅读器)可以明确地将图和说明联系在一起。

figure 元素不只可以显示图片。还可以使用它给 audiovideoiframeobjectembed 元素加说明。

dialog

dialog 元素表示几个人之间的对话。HTML 5 dt 元素可以表示讲话者,HTML 5 dd 元素可以表示讲话内容。所以,在老式浏览器中也可以以合理的方式显示对话。清单 7 显示在 Galileo 的 “Dialogue Concerning the Two Chief World Systems” 上的一段著名对话。


清单 7. 用 HTML 5 编写的 Galilean 对话
                
<dialog>
	<dt>Simplicius </dt> 
    <dd>According to the straight line AF,
	and not according to the curve, such being already excluded
	for such a use.</dd>

	<dt>Sagredo </dt> 
    <dd>But I should take neither of them,
	seeing that the straight line AF runs obliquely. I should
	draw a line perpendicular to CD, for this would seem to me
	to be the shortest, as well as being unique among the
	infinite number of longer and unequal ones which may be
	drawn from the point A to every other point of the opposite
	line CD. </dd>

	<dt>Salviati </dt> 
    <dd><p> Your choice and the reason you
	adduce for it seem to me most excellent. So now we have it
	that the first dimension is determined by a straight line;
	the second (namely, breadth) by another straight line, and
	not only straight, but at right angles to that which
	determines the length. Thus we have defined the two
	dimensions of a surface; that is, length and breadth. </p>

	<p> But suppose you had to determine a height—for
	example, how high this platform is from the pavement down
	below there. Seeing that from any point in the platform we
	may draw infinite lines, curved or straight, and all of
	different lengths, to the infinite points of the pavement
	below, which of all these lines would you make use of? </p>
	</dd>
</dialog>

对于这个元素的准确语法还有争议。一些人希望在 dialog 元素中嵌入非对话文本(比如剧本中的舞台说明),还有人不喜欢扩展 dtdd 元素的作用。尽管在具体语法方面有争议,但是大多数人都认为以这样的语义性方式表达对话是好事情。





回页首


语义性内联元素

HTML 4 用 5 个不同的内联元素表示略有差异的计算机代码:varcodekbdttsamp。但是,它无法表示时间、数字等基本数值。HTML 5 提供了几个新的内联元素来满足非技术作者的需求。

m

m 元素表示文本被 “加上标志”,但是不一定要强调。可以把它想像成书中突出显示的一节。Google 的缓存页面就是典型的用例。如果链接到一个缓存的副本,搜索词就被加上标志。例如,如果搜索 “Egret”,那么缓存的 Google 页面可能像下面这样:

The Great <m>Egret</m> (also known as the
American <m>Egret</m>)  is a large white wading bird found worldwide.
The Great <m>Egret</m> flies with slow wing beats. The
scientific name of the Great <m>Egret</m> is <i>Casmerodius
albus</i>.

对于这个元素的名称当前还有争议。在规范发布之前,它可能从 m 改为 mark

time

time 元素表示一个时间值,比如 5:35 P.M., EST, April 23, 2007。例如:

<p>I am writing this example at
<time>5:35 P.M. on April 23rd</time>.
</p>

time 元素可以帮助浏览器和其他程序识别出 HTML 页面中的时间。它不要求对元素内容应用任何特定的格式。但是,每个 time 元素都应该有一个 datetime 属性,其中包含更适合机器识别的时间值,比如:

<p>I am writing this example at
<time datetime="2007-04-23T17:35:00-05:00">5:35 P.M. on April 23rd</time>.
</p>

适合机器读取的时间值可能对搜索引擎、日历程序等有帮助。

meter

meter 元素表示指定范围内的数字值。例如,可以用它表示薪水、投票给 Le Pen 的法国选民的百分比或考试分数。在这里,我使用 meter 标出 Software Development 2007 上一位 Google 程序员提供的数据:

<p>An entry level programmer in Silicon Valley 
can expect to start around <meter>,000</meter> per year.
</p>

meter 元素帮助浏览器和其他客户机识别 HTML 页面中的数量。它不要求对元素内容应用任何特定的格式。但是,每个 meter 元素可以有最多 6 个属性,它们按照更适合机器识别的形式表示这个数量:

  • value
  • min
  • low
  • high
  • max
  • optimum

这些属性都应该包含一个十进制数字。例如,期末考试的分数可以写成下面这样:

<p>Your score was 
<meter value="88.7" min="0" max="100" low="65" high="96" optimum="100">B+</meter>.
</p>

这表示这个学生的分数是百分制中的 88.7。可能的最低分数是 0,但是实际的最低分数是 65。可能的最高分数是 100,但是实际的最高分数是 96。用户代理可以用某种数值控件显示这一信息,也可以在工具提示中显示额外的数据,但是最常见的情况可能是像其他内联元素一样对它应用样式。

progress

progress 元素表示一个正在进行的过程的状态,就像图形用户界面(GUI)应用程序中的进度条。例如,可以用它表示一个文件已经下载的百分比或者播放电影时的当前位置。下面这个进度控件表示下载已经完成了 33%:

<p>Downloaded: 
  <progress value="1534602" max="4603807">33%</progress>
</p>

value 属性表示操作的当前状态。max 属性表示操作的总量。这个元素指出要下载的数据总量是 4,603,807 字节,已经下载了 1,534,602 字节。

忽略 max 属性,就可以显示无限的进度。

在操作进行时,应该使用 JavaScript 语言动态地更新进度条。在静态情况下,这个元素没什么意义。





回页首


内嵌的媒体

视频已经在 Web 上广泛流行了,但是其格式几乎都是专有的。YouTube 使用 Flash,Microsoft 使用 Windows Media®,Apple 使用 QuickTime。在一种浏览器中用来嵌入这些内容的标记在另一种浏览器中是无效的。因此,WhatWG 提议引入一个新的 video 元素,用来嵌入任意视频格式。例如,可以用以下代码嵌入我的 QuickTime 电影 “a Sora in Prospect Park”:

<video src="http://www.cafeaulait.org/birds/sora.mov" />
  

对于以哪种格式和解码器作为首选,仍然有争议。可能会强力推荐或要求使用 Ogg Theora。还可以可选地支持 QuickTime 等专有格式和 MPEG-4 等受专利限制的格式。实际使用的格式很可能由市场决定,就像是 GIF、JPEG 和 PNG 格式那样(这些格式通过市场竞争压倒了 BMP、X-Bitmap 和 JPEG 2000 等竞争者,成为 img 元素的首选格式)。

还提议引入 audio 元素。例如,可以使用以下代码给 Web 页面加上背景音乐:

<audio src="spacemusic.mp3"
    autoplay="autoplay" loop="20000" />
  

autoplay 属性指示浏览器在装载页面后立即开始播放,而不等待明确的用户请求。音频循环播放 20,000 次,然后停止(或者在用户关闭窗口或转到另一个页面时停止)。当然,浏览器可以(而且应该)允许用户关闭内嵌的媒体,不应该只按页面作者的要求去做。

浏览器必须支持 WAV 格式,还可以支持 MP3 等其他格式。

因为老式浏览器不支持这些元素,而且它们对于盲人和聋人用户来说没有意义,所以 audiovideo 元素可以包含额外的标记,用来描述音频和视频的内容。这对搜索引擎也有帮助。在理想情况下,这些标记是音频和视频内容的完整文字版本。例如,清单 8 显示 John F. Kennedy 的就职演说。


清单 8. 用 HTML 5 编写的 John F. Kennedy 的就职演说
                
<audio src="kennedyinauguraladdrees.mp3">
    <p>
    Vice President Johnson, Mr. Speaker, Mr. Chief Justice,
    President Eisenhower, Vice President Nixon, President Truman,
    Reverend Clergy, fellow citizens:
    </p>
    
    <p>
    We observe today not a victory of party, but a celebration of
    freedom -- symbolizing an end, as well as a beginning -- 
   signifying renewal, as well as change. For I have sworn before
    you and Almighty God the same solemn oath our forebears
    prescribed nearly a century and three-quarters ago.
    </p>
    
    <p>
    The world is very different now. For man holds in his mortal
    hands the power to abolish all forms of human poverty and all
    forms of human life. And yet the same revolutionary beliefs for
    which our forebears fought are still at issue around the globe -- 
    the belief that the rights of man come not from the
    generosity of the state, but from the hand of God.
    </p>
    
    <p>
    ...
    </p>
    
    </audio>





回页首


交互

HTML 5 也被称为 Web Applications 1.0。为了实现这个目标,增加了几个为 Web 页面提供交互体验的新元素:

  • details
  • datagrid
  • menu
  • command

这些元素都可以根据用户的操作和选择改变显示的内容,而不需要从服务器装载新页面。

details

details 元素表示在默认情况下可能不显示的详细信息。可选的 legend 元素可以提供详细信息的摘要。details 元素的用途之一是提供脚注和尾注。例如:

The bill of a Craveri's Murrelet is about 10% thinner 
than the bill of a Xantus's Murrelet. 
<details>
<legend>[Sibley, 2000]</legend>
<p>Sibley, David Allen, The Sibley Guide to Birds, 
(New York: Chanticleer Press, 2000) p. 247
 </p>
</details>

没有指定具体的显示方式。浏览器可以选用脚注、尾注和工具提示等方式。

每个 details 元素可以有一个 open 属性。如果设置了这个属性,那么详细信息在最初就显示出来。如果没有设置这个属性,那么会隐藏它们,直到用户要求显示它们。无论是哪种情况,用户都可以通过单击一个图标或其他控件来显示或隐藏详细信息。

datagrid

datagrid 元素提供一个网格控件。可以用它显示树、列表和表格,用户和脚本可以更新这些界面元素。与之相反,传统的表格主要用来显示静态数据。

datagrid 从它的内容(一个 tableselect 或其他 HTML 元素)获得初始数据。例如,清单 9 中的 datagrid 包含一张成绩表。在这个示例中,datagrid 的数据来自一个 table。更简单的一维 datagrid 可以从 select 元素获得数据。如果使用其他 HTML 元素,那么每个子元素成为网格中的一行。


清单 9. 成绩表 datagrid
                
<datagrid>
  <table>
    <tr><td>Jones</td><td>Allison</td><td>A-</td><td>B+</td><td>A</td></tr>
    <tr><td>Smith</td><td>Johnny</td><td>A</td><td>C+</td><td>A</td></tr>
    <tr><td>Willis</td><td>Sydney</td><td>C-</td><td>D</td><td>F</td></tr>
    <tr><td>Wilson</td><td>Frank</td><td>B-</td><td>B+</td><td>A</td></tr>
  </table>
</datagrid>

这个元素与常规表格的区别在于,用户可以选择行、列和单元格;把行、列和单元格折叠起来;编辑单元格;删除行、列和单元格;对网格排序;以及在客户机浏览器中直接进行其他数据操作。可以用 JavaScript 代码监视更新。Document Object Model(DOM)中增加了 HTMLDataGridElement 接口以支持这个元素(清单 10)。


清单 10. HTMLDataGridElement
                
interface HTMLDataGridElement : HTMLElement {
           attribute DataGridDataProvider data;
  readonly attribute DataGridSelection selection;
           attribute boolean multiple;
           attribute boolean disabled;
  void updateEverything();
  void updateRowsChanged(in RowSpecification row, in unsigned long count);
  void updateRowsInserted(in RowSpecification row, in unsigned long count);
  void updateRowsRemoved(in RowSpecification row, in unsigned long count);
  void updateRowChanged(in RowSpecification row);
  void updateColumnChanged(in unsigned long column);
  void updateCellChanged(in RowSpecification row, in unsigned long column);
};

还可以使用 DOM 在网格中动态地装载数据。也就是说,datagrid 可以不包含那些提供初始数据的子元素。可以用一个 DataGridDataProvider 对象设置它(清单 11)。这样就可以从数据库、XmlHttpRequest 或者 JavaScript 代码能够访问的任何资源装载数据。


清单 11. DataGridDataProvider
                
interface DataGridDataProvider {
  void initialize(in HTMLDataGridElement datagrid);
  unsigned long getRowCount(in RowSpecification row);
  unsigned long getChildAtPosition(in RowSpecification parentRow, 
      in unsigned long position);
  unsigned long getColumnCount();
  DOMString getCaptionText(in unsigned long column);
  void getCaptionClasses(in unsigned long column, in DOMTokenList classes);
  DOMString getRowImage(in RowSpecification row);
  HTMLMenuElement getRowMenu(in RowSpecification row);
  void getRowClasses(in RowSpecification row, in DOMTokenList classes);
  DOMString getCellData(in RowSpecification row, in unsigned long column);
  void getCellClasses(in RowSpecification row, in unsigned long column, 
      in DOMTokenList classes);
  void toggleColumnSortState(in unsigned long column);
  void setCellCheckedState(in RowSpecification row, in unsigned long column, 
      in long state);
  void cycleCell(in RowSpecification row, in unsigned long column);
  void editCell(in RowSpecification row, in unsigned long column, in DOMString data);
};

menu 和 command

menu 元素实际上在 HTML 2 中就出现了。在 HTML 4 中废弃了它,但是 HTML 5 又恢复了它并指定了新的意义。在 HTML 5 中,menu 包含 command 元素,每个 command 元素引发一个操作。例如,清单 12 是一个弹出警告框的菜单。


清单 12. HTML 5 菜单
                
<menu>
    <command onclick="alert('first command')"  label="Do 1st Command"/>
    <command onclick="alert('second command')" label="Do 2nd Command"/>
    <command onclick="alert('third command')"  label="Do 3rd Command"/>
</menu>

还可以用 checked="checked" 属性将命令转换为复选框。通过指定 radiogroup 属性,可以将复选框转换为单选按钮,这个属性的值是互相排斥的按钮的组名。

除了简单的命令列表之外,还可以使用 menu 元素创建工具栏或弹出式上下文菜单,这需要将 type 属性设置为 toolbarpopup。例如,清单 13 显示一个与 WordPress 等 blog 编辑器相似的工具栏。它使用 icon 属性链接到按钮的图片。


清单 13. HTML 5 工具栏
                
<menu type="toolbar">
    <command onclick="insertTag(buttons, 0);"  label="strong" icon="bold.gif"/>
    <command onclick="insertTag(buttons, 1);"  label="em" icon="italic.gif"/>
    <command onclick="insertLink(buttons, 2);" label="link" icon="link.gif"/>
    <command onclick="insertTag(buttons, 3);"  label="b-quote" icon="blockquote.gif"/>
    <command onclick="insertTag(buttons, 4);"  label="del" icon="del.gif"/>
    <command onclick="insertTag(buttons, 5);"  label="ins" icon="insert.gif"/>
    <command onclick="insertImage(buttons);"   label="img" icon="image.gif"/>
    <command onclick="insertTag(buttons, 7);"  label="ul" icon="bullet.gif"/>
    <command onclick="insertTag(buttons, 8);"  label="ol" icon="number.gif"/>
    <command onclick="insertTag(buttons, 9);"  label="li" icon="item.gif"/>
    <command onclick="insertTag(buttons, 10);" label="code" icon="code.gif"/>
    <command onclick="insertTag(buttons, 11);" label="cite" icon="cite.gif"/>
    <command onclick="insertTag(buttons, 12);" label="abbr" icon="abbr.gif"/>
    <command onclick="insertTag(buttons, 13);" label="acronym" icon="acronym.gif"/>
</menu>

label 属性提供菜单的标题。例如,清单 14 显示一个 Edit 菜单。


清单 14. HTML 5 Edit 菜单
                
<menu type="popup" label="edit">
    <command onclick="undo()"   label="Undo"/>
    <command onclick="redo()"   label="Redo"/>
    <command onclick="cut()"    label="Cut"/>
    <command onclick="copy()"   label="Copy"/>
    <command onclick="paste()"  label="Paste"/>
    <command onclick="delete()" label="Clear"/>
</menu>

菜单可以嵌套在其他菜单中,形成层次化的菜单结构。





回页首


结束语

HTML 5 是未来的 Web 的一部分。它的新元素会产生更干净更简单的代码,让页面更容易理解。Divspan 仍然有用处,但是不会像以前那样频繁地使用它们了。许多页面不再需要它们了。

分享这篇文章……

digg 将这篇文章提交到 Digg
del.icio.us 发布到 del.icio.us
Slashdot 提交到 Slashdot!

尽管目前并非所有浏览器都支持这些元素,但这是 HTML 引入大多数新元素之后的普遍情况,比如 imgtableobject 等等。随着时间的推移,支持会逐渐完善。浏览器会忽略不认识的 HTML 元素,这意味着老式浏览器的用户仍然能够阅读 HTML 5 页面,他们的浏览方式与以前一样。现代浏览器的用户可以获得更好的用户体验,但是没有人会由于 HTML 5 新元素而妨碍浏览。

用 8 年时间等待新特性的出现实在是够漫长的,尤其是在快速变化的 Web 世界中。在 Web 时代的早期,Netscape、Microsoft 和其他公司几乎每周都会引入新元素,HTML 5 终于也为我们提供了一些令人兴奋的东西。同时,它以一种谨慎得多的方式定义这些元素,让我们可以放心地使用它们。前景是光明的。



参考资料

学习

获得产品和技术
  • IBM 试用版软件:使用这些可以从 developerWorks 直接下载的试用软件构建您的下一个开发项目。


讨论


关于作者

Photo of Elliot Rusty Harold

Elliotte Harold 出生在新奥尔良,现在他还定期回老家喝一碗美味的秋葵汤。但目前他和妻子 Beth、他们的狗 Shayna、猫 Charm 和 Marjorie 定居在布鲁克林附近的 Prospect Heights。他是 Polytechnic 大学的计算机科学副教授,讲授 Java 和面向对象编程。他的 Cafe au Lait Web 站点是 Internet 上最受欢迎的独立 Java 站点之一,子站点 Cafe con Leche 是最受欢迎的 XML 站点之一。他的著作包括 Effective XML Processing XML with Java Java Network Programming The XML 1.1 Bible 。他的最新著作是 Java I/O, 第二版。他目前从事 XOM API 处理 XML、Jaxen XPath 引擎和 Jester 测试覆盖工具的研究。



 
MAY梅 @ 2008-04-22 10:49

网页PNG透明支持(IE6、IE7、firefox下测试通过)
IE6不支持PNG半透明图片的缺陷为web设计带来了极大的不便,之前曾经介绍过用滤镜+hack的方法实现显示PNG,不过实现起来相当繁琐。还有一种网上比较流行的方法,更加简便,下面详细介绍这种方法:

把以下代码保存为correctpng.js
function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
   var img = document.images[i]
   var imgName = img.src.toUpperCase()
   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
   {
   var imgID = (img.id) ? "id='" + img.id + "' " : ""
   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
   var imgStyle = "display:inline-block;" + img.style.cssText
   if (img.align == "left") imgStyle = "float:left;" + imgStyle
   if (img.align == "right") imgStyle = "float:right;" + imgStyle
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
   var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
   img.outerHTML = strNewHTML
   i = i-1
   };
   };
};

if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};

在网页的头部引用一下
<SCRIPT language=JavaScript
src="correctpng.js"
type=text/javascript></SCRIPT>

使用的时候直接用img标签即可。


 
MAY梅 @ 2008-03-19 12:18



 
MAY梅 @ 2008-02-26 15:17

Flash 的全屏技术一、不用浏览器直接用Flash播放器播放:

A. 不显示Flash播放器菜单栏的全屏(类似屏保效果),在第一帧处的Actions用FS Command命令,在For standalone player选项中选择fullscreen,这时就会看到arguments中为true,Command中是fullscreen。运行中可按ESC退出或设一按钮在Actions上,用FS command在For standalone player选项中选择quit也可退出。附带说一句:For standalone player上的所有选项只适合于用Flash播放器播放的情况。在浏览Flash动画时,如果按CTRL+F键,可实现全屏与非全屏的切换。

B. 如果仅是要使swf文件占满Flash播放器的窗口,什么也不需要做。直接击swf文件。
以上一类全屏多用在非互联网环境的运行。

二、在非Flash播放器(如IE)中运行:

A. 只占满浏览器:这种情况相对简单,不管你制作的Flash大小是否为800×600,只要在调用swf文件的HTML中将WIDTH和HEIGHT的参数设为100%即可,当然也可以在Flash导出HTML文件的设置中进行设置,方法是:打开File菜单;选Publish Settings弹出导出设置对话框;在HTML标签下的Dimensions选项,下拉后选中Percent(百分比),并在WIDTH和HEIGHT框中填100,运行这个与swf同名的HTML文件则与直接加语句效果相同。这种占满浏览器的全屏与swf文件的设置无关,但最好设置的大小在700×400左右,否则容易导致图像(主要是在Flash中调用的位图)、汉字的失真。

B. 不显示浏览器菜单栏、工具栏的全屏。这种全屏稍稍复杂,与Flash的设置无关,但要借助JavaScript来完成。方法是:在HTML文件中的与之间加入以下代码也可以在swf文件的第一帧Actions上的URL命令上加上

javascript:window.open("*.swf"," ","fullscreen=1,menubar=no")

这种全屏类似屏保,需要用ALT+F4或设置按钮退出。把fullscreen设为=0,则是显示浏览器菜单栏、工具栏的全屏。(注:*.swf是你所要显示的Flash动画的文件名) 




FLASH 全屏有二类四种:
1、不用浏览器直接用FLASH播放器播放的类型:
A、不显示FLASH播放器菜单栏的全屏(类似屏保效果),在第一帧处的Actions用FS Command 命令,
在For standalone player 选项中选择fullscreen 为true 即可。运行中可按 ESC 退出或设一按钮
在Actions上用FS command ,在For standalone player 选项中选择quit 也可退出。附带说一句:
For standalone player上的所的选项只适合于用FLASH 播放器播放的情况。
B、如果仅是要使SWF文件占满FLASH播放器的窗口,什么也不需要做。直接击SWF文件。
以上一类全屏多用在非网络的运行。
2、第二类是在非FLASH 浏览器(如IE)中运行的全屏:
A、只占满浏览器:这种情况相对简单,不管您设的FLASH是否是800*600,只要在调用SWF文件的HTML文件中
将WIDTH= HEIGHT= 后面的两个参数设为100即可,当然也可以在FLASH 导出HTML文件的设置中进行设置,
方法是:打开FILE菜单:选Publish Settings 弹出导出设置对话框:在HTML标签下的Dimensions选项中
下拉后选中Percent,并在WIDTH 和HEIGHT 框中填100,运行这个与SWF同名的HTML文件则与直接加语句同
效。这种占满浏览器的全屏与SWF文件的设置无关,但最好设置的大小在700*400附近,否则容易导致图像
特别是汉字的失真。
B、不显示浏览器菜单栏、工具栏的全屏。这种全屏稍稍复杂,也与FLASH的设置无关,但要借助Javacript来
完成。方法是:在HTML文件中<head></head>间加入以下代码:
<script type="text/javascript">
<!--
window.open("nfd.swf","","fullscreen=1,menubar=no,width=800,height=600")
//-->
</script>
注:nfd.swf 改为您要播放的SWF文件名。
也可以在SWF文件的第一帧Actions上的URL 命令上加上:
javacript:window.open("nfd.swf","","fullscreen=1,menubar=no,width=800,height=600")
注:nfd.swf 改为您要播放的SWF文件名。
这种全屏也是类似屏保,用ALT+F4或设置按钮退出。把fullscreen设为=0,则只是不显示浏览器菜单栏、工具栏的全屏。

用 FLASH 的 player 播放时,即使没有设置 FSCOMMAND 也可以用 CTRL+F 的方式全屏播放。

好了,关于全屏的所有方法就是如此,您可以根据自己的需要试试看(以上以IE为例)。


 
MAY梅 @ 2007-12-25 02:22

Plants: 《秦时明月》
Plants: 《秦时明月》

秦时明月
中国制造~
中国第一部3d武侠动画片~
人物造型总算是很大程度的改变~
最近刚发现的~
支援下国产~
于是下载来看看~
如果纯粹是喜欢视觉效果的朋友~
建议还是不要看了~

配音真的是…………
还是日本的声优敬业……
镜头^^^^
看的人有眩晕感……
不要以为把画面变的模糊就有速度感……
还有提高声音速度弥补画面缺祯……
黑屏……白屏……红屏……
主人公看不到的……
注定观众也要看空白祯……

画面制造看不出是武侠动画……

唯一看点……
人物造型……

最后引用片头歌词一句

敢爱的人注定一身伤……
++++++++++++++++++++++++++++++++++++
投名状
金成武 刘德华 李连杰 徐静蕾
兄弟结拜
战争
野心
信任
背叛
感慨……
岁月不饶人……
金成武还是很年轻的感觉……

刚刚知道徐静蕾原来长那样……
++++++++++++++++++++++++++++++++++++++
火影忍者》看到261了……

神笔马良都出来了……

很佩服日本人的整合能力……



 
MAY梅 @ 2007-12-25 02:15

孩子要玩《仙剑奇侠4》游戏

于是在讯雷里找了

一个1.38G

下了半天的时间~

于是点击安装~

结果出来的界面是

街舞区》~~~~

挺纳闷的~

感觉应该是《街舞区》这游戏没

《仙剑奇侠4》好吧~

要不挂羊头卖狗肉~

关键给我个狗肉也好~

给个臭肉~

于是接着找~

找见一个~

2.38G的~

评论写的能下~

于是又下了~

下了1天的时间~

看看软件说明~

安装完了要去它们的站点下载破解程序~

去那站点搜了一下根本没那东西~

还要装个一个镜像工具~

于是在百度搜了一个~

下回来刚点安装~

瑞星开始做出强烈反映了~

感觉到问题的严重性~

于是又在百度里搜了下关于《仙剑奇侠4》

原来没有盗版~

有盗版的也不会发行出来给大家用的

网上说的破解的大多是木马病毒~

特别是那个破解程序本身就是个木马~

真SHIT~

看了下网上报价~

普通到豪华~

45元到150元钱~

正版的~

于是告诉孩子~

你真想玩的话就去买个正版的吧~

从早上就开始杀毒~

正常模式里杀~

100多个~~

杀完了又进安全模式继续杀~

已经成毒窝了~~

.........似乎又多删了东西了~

乱套了都~~~


重装系统装了1星期………………

装了两便……

关键是自己的系统盘不好使……

还要专程去借的……

 

 

 


 
MAY梅 @ 2007-12-08 06:32

Plants: 拙笔奋进
Plants: 拙笔奋进
Plants: 拙笔奋进


 
MAY梅 @ 2007-12-02 07:24

最近讨论最多的就是结婚的话题~

看同学海边的结婚照~

讨论未来老公的问题~

世界上还是穷人占决大部分的~

考虑以后将如何在贫穷中生活~

平平淡淡的贫穷~

不会衣不遮体

亦不会享受所谓的高档~

不会食不果腹~

亦不会鲍鱼龙虾的度日~

+++++++++++++++++++++++++++++++++

坚持了两日的早睡早起~

早睡造成的后果就是起的太早~

下午就会犯困~

可是早上是清醒的~

本来昨天中午想睡个午觉~

结果是睡了就不想起来了~

晚上10点睡的清醒了~

起来画了张画~

然后感慨下人生~

++++++++++++++++++++++++++++++++++

丑闻》韩

看明白一个道理~

一个坏人一但是转了性~变成好人了~

那他就是离死不远了~

这似乎是电影电视剧里最常出现的人生哲理~~

++++++++++++++++++++++++++++++++++

公主小妹》 连续剧~

一个穷妹妹~

突然有一天~

天上掉下来个亚洲首富的老爷爷~

跟天上掉馅饼一个道理~

出现的可能行几乎为零~

没事看看~

应该是女人的憧憬~

又有钱又有帅哥追~

哈哈~

+++++++++++++++++++++++++++++++++++

地狱神探

黑客帝国》的男人演的~

还看见了《越狱》里的那个剪了迈克一个脚指头的男人~

还有《木乃伊归来》里面那个女主角~~

讲的关于进天堂的事情~

信仰太浓烈的容易成变态疯子~

没信仰的容易被变态疯子宰杀~

恐怖的事实~

看《寂寞岭》得出的理念~



 
MAY梅 @ 2007-12-02 06:57

Plants: 拙笔奋进


 
MAY梅 @ 2007-12-02 03:10

Plants: 拙笔奋进


 
MAY梅 @ 2007-11-27 20:28

Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 水饺
Plants: 新发型

自制饺子

准备工作

1。饺子皮~30片左右重量1斤左右(菜市场买来现成的)
2。生鸡蛋
3。韭菜1两
4。肉馅3-4两(最好去超市买新鲜的)
5。食用油(最好是花生油,也可是大豆油,其它油个人做个人负责自己的胃吧)
6。盐
7。鸡精

制作过程

韭菜切成长度为5毫米的小段

与肉馅一起搅拌

加入生鸡蛋

加适量的油(让馅看起来有点软就可以了)

加适量盐与鸡精一起搅拌

然后用饺子皮一个一个的包起来就好了

哈哈


注意问题

关于饺子破肚~

饺子皮是中间厚四周薄

放馅放中间

尽量的隆起来

感觉馅放的就比较圆的~

然后从中间将皮拉到一起

捏实

再向两边慢慢捏实

尽量不要让要捏实的部分沾到馅~

……又开始馋了~

最喜欢韭菜馅的饺子啦~

还有韭菜鱼肉馅的~

鱼肉与大肉的制作区分就是要多放些油~~

啊啊~~~不行了~~馋出口水了~

好久没吃鱼肉馅的饺子啦~

昨天吃的还没消化完~

依然在查克拉过盛中~

2007112706:51

放上自己做的饺子军团图片~

嘿嘿~

还有先前答应的放上个人的新发型相片~

用手写板忙活的~

累的手抽筋~

象刚开始学习用鼠标一样~

总是抓不住它到底要跑哪~

现在总算熟练了~

然后发现一个问题~

我用PAINTER时那笔触总是很生硬

PHOTO就可以用画笔来改善~

于是突然发现

手写板的感压设置是最低~

原来一直在用错的设置~

总算一晚上没白忙活~

++++++++++++++++++++++++++++

目前的网很变态

只能上QQ

我又不聊QQ~~

似乎又开始感到饿了~

OH YA SI MI