Problems with the for attribute in the label

Source: Internet
Author: User

The label has a for attribute, which is used to associate with the form. However, the value of this for attribute can only be the id value in the form, not the value of the class.

Test 1

<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"/>

The test is normal. When you click the text, it will be selected

Test 2

<Label for = "male"> Male </label> <input type = "radio" name = "sex" class = "male"/> <br/> <label for = "female"> Female </label> <input type = "radio" name = "sex" class = "female"/>

The test does not respond. clicking the text radio button is not selected.

Conclusion: Pay attention to the subtle application of the for attribute in the label. Join form. The attribute value is the value of the Form id.

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.