為頁(yè)面上的其它元素指定標(biāo)簽。
Specifies a label for another element on the page.
要將 LABEL 綁定到其它的控件,請(qǐng)將 LABEL 元素的 FOR 屬性設(shè)置為與該控件的 ID 相同。將 LABEL 綁定到控件的 NAME 屬性毫無(wú)用處。但是,要提交表單,你必須為 LABEL 元素所綁定到的控件指定 NAME。
有兩種方法給所指定的快捷鍵添加下劃線。LABEL 元素的 rich text 支持可以在 ACCESSKEY 屬性所指定的快捷鍵字符兩側(cè)加上 U 元素。如果你更愿意使用樣式表(CSS)來(lái)應(yīng)用樣式,可以將該字符包含在 SPAN 中,并設(shè)置樣式為“text-decoration: underline”。
如果用戶單擊 LABEL,則會(huì)先觸發(fā) LABEL 上的 onclick 事件,然后觸發(fā)由 htmlFor 屬性所指定的控件上的 onclick 事件。按下 LABEL 設(shè)定的快捷鍵將設(shè)置焦點(diǎn)但并不觸發(fā) onclick 事件。
標(biāo)簽不允許嵌套。
此元素在 Internet Explorer 4.0 及以上版本的 HTML 和腳本中可用。
此元素是內(nèi)嵌元素。
此元素需要關(guān)閉標(biāo)簽。
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 屬性設(shè)置文本框的焦點(diǎn)。
This example uses the LABEL element and the ACCESSKEY attribute to set focus on a text box.
<LABEL FOR="oCtrlID" ACCESSKEY="1">
#<SPAN style="text-decoration:underline;">1</SPAN>: Press Alt+1 to set focus to textbox
</LABEL>
<INPUT TYPE="text" NAME="TXT1" VALUE="binding sample 1"
SIZE="20" TABINDEX="1" ID="oCtrlID">
聯(lián)系客服