Tutorial on using HTML label labels

Source: Internet
Author: User

In dreamweaver8, as long as a form or form object or text box is addedCodeAdd a <label> </label>. I have never understood what the label is. Today I see the explanation:
Two attributes in a label are very useful. One is for and the other is accesskey.
For attributes
Function: indicates the HTML element to be bound to a label. When you click this label, the bound element gets the focus.
Usage: <label for = "inputbox"> name </label> <input id = "inputbox" type = "text">

Accesskey attributes:
Function: access the hotkey of the element bound to the label. When you press the hotkey, the bound element gets the focus.
Usage: <label for = "inputbox" accesskey = "N"> name </label> <input id = "inputbox" type = "text">
Limitation: the shortcut keys set in the accesskey attribute cannot conflict with the shortcut keys of the browser. Otherwise, the shortcut keys of the browser are preferentially activated.

Note
To bind a label to another control, set the for Attribute of the label element to be the same as the ID of the control. Binding a label to the control's name attribute is useless. However, to submit a form, you must specify the name for the control bound to the label element.
There are two ways to underline the specified shortcut key. The Rich Text of the label element supports adding the U element to both sides of the shortcut key character specified by the accesskey attribute. If you prefer to use a style sheet (CSS) to apply a style, you can include the character in the span and set the style to "text-Decoration: underline ".

If you click label, The onclick event on the label is triggered first, and then the onclick event on the control specified by the htmlfor attribute is triggered. Pressing the shortcut key set by label sets the focus but does not trigger the onclick event.

Note:
1. labels cannot be nested.
2. This element is available in HTML and script of Internet Explorer 4.0 and later versions.
3. This element is an embedded element.
4. The label must be disabled for this element.

Element sample code
The following example uses the label element and accesskey attribute to set the focus of the text box.
<Label for = "octrlid" accesskey = "1">
<Span style = "text-Decoration: underline;"> name </span>: <font color = "#999999"> press Alt + 1 to text box </font>
</Label>
<Input type = "text" name = "txt1" value = "A Hui Nan" size = "20" tabindex = "1" id = "octrlid">
Demo:

<Textarea id = "runcode48150"> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <label for =" octrlid "accesskey =" 1 "> <br/> <span style =" text-Decoration: underline; "> name </span>: press Alt + 1 to the text box <br/> </label> <br/> <input type = "text" name = "txt1" value = "A Hui Nan" size =" 20 "tabindex =" 1 "id =" octrlid "> </textarea>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.