[Html5]label label usage and recommendations

Source: Internet
Author: User

The For property specifies which form element the label binds to. Implicit and explicit contact

Tags are typically associated with form controls in one of the following two ways: the form control as the content of the tag label, either implicitly, or by naming a target form ID for the for property under the <label> tag, which is an explicit form.

Explicit Contact:<label for= "SSN">Social Security Number:</label><inputtype= "text"name= "Socsecnum"ID= "SSN" />Implicit Contact:<label>Date of Birth:<inputtype= "text"name= "DOFB" /></label>

The first tag is to associate the text "Social Security Number:" With the text input control ("Socsecnum") of the form's Social Security numbers in an explicit form, with the value of the for property being the same as the ID of the control, which is SSN. The second tag ("Date of Birth:") does not require a for property, and its related controls do not require an id attribute, which is implicitly connected by placing the <input> tag in the <label> tag.

The new form property in HTML5:

The form property specifies one or more forms to which the label belongs.

The value of the form property must be the ID of the form to which it belongs.

If you want to refer to more than one form, use a space-delimited list.

Recommendation: It is not recommended to use the Form property, which is actually tested, even if you do not use the form property to point to the form or to the elements within the form, because the ID of the page element is unique, and you do not need a form to differentiate which form the label belongs to.

So if you can guarantee that the page element ID is unique, then only with the For property, if the page element ID is not guaranteed to be the only recommended use implicit binding even if the target element ID is not repeated (if you want to use the form property to solve this situation, you will find that the form property does not work at all, The function is also the for property, which points to the first occurrence of the duplicate ID element).

Just when the form attribute doesn't exist, it doesn't work at all.

[Html5]label label usage and recommendations

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.