For attributes of HTML label labels

Source: Internet
Author: User

Background:

The Code is as follows:

 <P>
<Label for = "code"> employee ID (*): </label>
<Input id = "code" name = "code" type = "text"/>
</P>

What is the relationship between the for in the label and the ID in the input? I also got stuck. It seems that the Foundation is not good... so I went to Google.

Introduction:

The label Label defines the annotation (TAG) for the input element, which improves the usability for the mouse user. If you click Text in the label element, this control is triggered. That is to say, when the user selects the tag, the browser automatically redirects the focus to the form control related to the tag.

The for Attribute of the label should be the same as the ID attribute of the relevant element.

Test code:

Code

 <Div>
<Label for = "code"> Test 1 </label>
<Input id = "code"/>
</Div>
<Div>
<Label> Test 2 </label>
<Input id = "text1"/>
</Div>
<Div>
<Label for = "Nan"> male </label>
<Input type = "checkbox" id = "Nan"/>
<Label for = "NV"> female </label>
<Input type = "checkbox" id = "NV"/>
</Div>

:

  

Result:

When you click the text, the associated selection box and input box are selected.

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.