Skip navigation.

踩 IE

I hate IE forever.

简述 label 标签的用法

直接引用 MSDN 的上的描述

使用 LABEL 对象

HTML 4.0 规范引入了 LABEL 对象,您可以使用它来将文本与其他任何 HTML 对象或内部控件相关联。无论用户单击 LABEL 或者 HTML 对象,链接的 LABEL 和 HTML 对象在引发和接收事件时行为一致。要链接 LABEL 和 HTML 对象,请将 LABEL 的 FOR 属性设置为等于 HTML 对象的 ID 属性。

下列示例将 LABEL 控件与文本框相关联。当用户单击 LABEL 控件(或者按下 ALT+T 组合键)时,LABEL 控件会将焦点设置到文本框:

<label for="txtInputBox"><u>T</u>ype value:</label>
<input type="text" id="txtInputBox" name="txtInputBox" accesskey="t" />

label 主要是给表单组件增加可访问性设计的,一般我们都把 label 用在表单里。除以上方法,还可以直接用 label 套嵌整个表单组件和文本标签,如下面的例子:
<form action="..." method="post">
<p>
<label>
   First Name
   <input type="text" name="firstname" />
</label>
<label>
   <input type="text" name="lastname" />
   Last Name</label>
</p>
</form>

根据 规范 这样文本会自动与邻接的表单组件关联,遗憾的是 IE 并不支持这个特性。

第一届北京CSSer网页标准聚会最小高度100%,页脚保持在底部的布局方法

Comments

old9 29. April 2006, 02:17

对第二种嵌套表单组件的方法一直拿不准,等下再琢磨一下规范和DTD。

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

November 2009
S M T W T F S
October 2009December 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30