The use of HTML label Tags Tutorial _ Basic Tutorial

Source: Internet
Author: User

In Dreamweaver8, as soon as you add a form or Form object, a text box, and so on, you add a <label></label&gt to the code, and you never know what the label does, and today you just see the explanation:
There are two properties in the Label that are useful, one for, and the other for accesskey.
For property
Function: Represents the HTML element to which the label label is bound, and when you click on the tag, the element that is bound gets the focus.
Usage: <label for= "InputBox" > Name </label><input id= "InputBox" type= "text" >

AccessKey Properties:
Function: A hotkey that accesses the elements that the label label binds to, and when you press the hotkey, the bound element gets the focus.
Usage: <label for= "InputBox" accesskey= "N" > Name </label><input id= "InputBox" type= "text" >
Limitations: The shortcut key set by the AccessKey property cannot conflict with the browser's shortcut key, or the browser's shortcut key will be activated first.

Comments
To bind a label to another control, set the for property of the label element to be the same as the ID of the control. It is useless to bind a LABEL to the control's NAME property. However, to submit the form, you must specify name for the control to which the LABEL element is bound.
There are two ways to underline the shortcut keys you specify. Rich-text support for a LABEL element can add a U element on both sides of the shortcut key character specified by the ACCESSKEY property. If you prefer to use style sheets (CSS) to apply styles, you can include the character in SPAN and set the style to "Text-decoration:underline".

If the user clicks a label, the onclick event on the label is triggered first, and then the OnClick event on the control specified by the Htmlfor property is triggered. Pressing the shortcut key set by the LABEL sets the focus but does not trigger the onclick event.

Places to look for:
1, the label is not allowed to nest.
2, this element is available in Internet Explorer 4.0 and above versions of HTML and scripts.
3, this element is an inline element.
4, this element needs to close the label.

Element Sample Code
The following example uses the LABEL element and the ACCESSKEY property to set the focus of the text box.
<label for= "Octrlid" accesskey= "1" >
<span style= "Text-decoration:underline;" > Name </span&gt: <font color= "#999999" > Press alt+1 to text box </font>
</LABEL>
<input type= "text" name= "TXT1" value= "A Will Nan" size= "" tabindex= "1" id= "Octrlid" >
Demonstrate:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" > <ptml> <pead> ; <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <title>html label function </title> </pead> <body> <l ABEL for= "Octrlid" accesskey= "1" > <span > Name </span>: <font color= "#999999" > Press alt+1 to text box </fo nt> </LABEL> <input type= "text" name= "TXT1" value= "O ' nan" size= "tabindex=" 1 "id=" Octrlid "> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.