HTML元素 - label




Specifies a label for another element on the page.


要将 LABEL 绑定到其它的控件,请将 LABEL 元素的 FOR 属性设置为与该控件的 ID 相同。将 LABEL 绑定到控件的 NAME 属性毫无用处。但是,要提交表单,你必须为 LABEL 元素所绑定到的控件指定 NAME。

有两种方法给所指定的快捷键添加下划线。LABEL 元素的 rich text 支持可以在 ACCESSKEY 属性所指定的快捷键字符两侧加上 U 元素。如果你更愿意使用样式表(CSS)来应用样式,可以将该字符包含在 SPAN 中,并设置样式为“text-decoration: underline”。

如果用户单击 LABEL,则会先触发 LABEL 上的 onclick 事件,然后触发由 htmlFor 属性所指定的控件上的 onclick 事件。按下 LABEL 设定的快捷键将设置焦点但并不触发 onclick 事件。


此元素在 Internet Explorer 4.0 及以上版本的 HTML 和脚本中可用。



To bind a LABEL to another control, set the FOR attribute of the LABEL element equal to the ID of the control. Binding a LABEL to the NAME attribute of the control has no effect. However, to submit a form, you must specify a NAME on the control to which the LABEL element is being bound.

There are two ways to underline the designated access key. The rich text support in the LABEL element makes it possible to wrap the U element around the character in the label text specified by the ACCESSKEY attribute. If you prefer to use cascading style sheets (CSS) to apply style formatting, enclose the designated character in a SPAN and set the style to "text-decoration: underline".

If the user clicks the LABEL, the onclick event fires on the LABEL and then on the control specified by the htmlFor property. Pressing the access key for the LABEL sets the focus but does not fire the onclick event.

Labels cannot be nested.

This element is available in HTML and script as of Internet Explorer 4.0.

This element is an inline element.

This element requires a closing tag.


下面的例子使用了 LABEL 元素和 ACCESSKEY 属性设置文本框的焦点。

This example uses the LABEL element and the ACCESSKEY attribute to set focus on a text box.


#<SPAN style="text-decoration:underline;">1</SPAN>: Press Alt+1 to set focus to textbox


<INPUT TYPE="text" NAME="TXT1" VALUE="binding sample 1"

SIZE="20" TABINDEX="1" ID="oCtrlID">