HTML & lt; label & gt; label for Attributes

Source: Internet
Author: User

Definition and usage

The for Attribute specifies the form element to which the label is bound.

Implicit and explicit connections

One of the following methods is usually used to associate the Form Control: the form control is used as the content of the tag, which is an implicit form, you can also name a target form id for the for Attribute under the <label> label. This is an explicit form.

For example, in XHTML:

Explicit contact:


[Html]
<Label for = "SSN"> Social Security Number: </label>
<Input type = "text" name = "SocSecNum" id = "SSn"/>

<Label for = "SSN"> Social Security Number: </label>
<Input type = "text" name = "SocSecNum" id = "SSn"/>

Implicit contact:


[Html]
<Label> Date of Birth: <input type = "text" name = "DofB"/> </label>

<Label> Date of Birth: <input type = "text" name = "DofB"/> </label>


The first tag is to explicitly associate the text "Social Security Number:" With the form's Social Security Number input control ("SocSecNum, the value of its for attribute is the same as the control id, which is SSN. The second tag ("Date of Birth:") does not require the for attribute, and its related controls do not require the id attribute, they are implicitly connected by placing the <input> label in the <label> label.

Instance

A simple HTML form with two input fields and related tags:

[Html]
<Form>
<Label for = "male"> Male </label>
<Input type = "radio" name = "sex" id = "male"/>
<Br/>
<Label for = "female"> Female </label>
<Input type = "radio" name = "sex" id = "female"/>
</Form>

<Form>
<Label for = "male"> Male </label>
<Input type = "radio" name = "sex" id = "male"/>
<Br/>
<Label for = "female"> Female </label>
<Input type = "radio" name = "sex" id = "female"/>
</Form>


 

Related Article

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.